本帖最后由 Alice 于 2016-5-20 09:01 编辑
代码的问题,根据你的代码。
首先,你的DataTable里是没有数据的。
其次,C1ComboBox的绑定DataTable应该这样设置:
- this.c1ComboBox2.ItemsDataSource = dt.DefaultView;
- this.c1ComboBox2.ItemsDisplayMember = "Col1";
- this.c1ComboBox2.ItemsValueMember = "Col1";
复制代码
其实,C1ComboBox数据绑定的数据应该从DataTable中添加,而不是通过非绑定模式的Items.Add直接添加。
你所指定的"a","b","c"应该是你DataTable中的Col1中的值。
所以代码应该是这样的:
- DataTable dt = new DataTable();
- for(int i =1;i<10;i++)
- {
- dt.Columns.Add("Col" + i.ToString());
- }
- string[] values = new string[] { "a", "b", "c", "d", "e", "f" };
- for(int i = 0;i< values.Length;i++)
- {
- dt.Rows.Add(new object[]{values[i]});
- }
- this.c1FlexGrid1.DataSource = dt.DefaultView;
- this.c1ComboBox2.ItemsDataSource = dt.DefaultView;
- this.c1ComboBox2.ItemsDisplayMember = "Col1";
- this.c1ComboBox2.ItemsValueMember = "Col1";
- c1ComboBox2.ItemsImageList = imageList2;
复制代码 |