日期:2014-05-18  浏览次数:20802 次

如何绑定combobox和dictionary?
winform
  Dictionary<string,string> picSource = new Dictionary<string,string>();
  picSource.Add("图片1","01.jpg");
  picSource.Add("图片2","02.jpg");
  cbbBackPic.DataSource = picSource;
  cbbBackPic.DisplayMember = "Key";
  cbbBackPic.ValueMember = "Value";
提示“复杂的 DataBinding 接受 IList 或 IListSource 作为数据源。”
如何解决?

------解决方案--------------------
C# code

      System.Collections.Generic.Dictionary<string, string> picSource = 
        new System.Collections.Generic.Dictionary<string, string>();
      picSource.Add("图片1", "01.jpg");
      picSource.Add("图片2", "02.jpg");
      BindingSource bs = new BindingSource();
      bs.DataSource = picSource;
      cbbBackPic.DataSource = bs;
      cbbBackPic.DisplayMember = "Key";
      cbbBackPic.ValueMember = "Value";