首页 新闻 赞助 找找看

c#checkedlistbox和dataGridView的问题

0
[已关闭问题] 关闭于 2017-04-08 22:14

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++) { dataGridView1.Rows[row].Cells[1].Value = checkedListBox1.CheckedItems[i].ToString(); } row++;//row为全局变量,public int row = 0; } private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dataGridView1.DataSource = dt; dt.Columns.Add("One", typeof(int)); dt.Columns.Add("Tow", typeof(string)); dt.Rows.Add("1");dt.Rows.Add("5"); dt.Rows.Add("2");dt.Rows.Add("6"); dt.Rows.Add("3");dt.Rows.Add("7"); dt.Rows.Add("4"); dt.Rows.Add("8"); this.checkedListBox1.Items.Add("aa"); this.checkedListBox1.Items.Add("bb"); this.checkedListBox1.Items.Add("cc"); this.checkedListBox1.Items.Add("dd"); this.checkedListBox1.Items.Add("ee"); this.checkedListBox1.Items.Add("ff"); this.checkedListBox1.Items.Add("gg"); this.checkedListBox1.Items.Add("hh"); }

 

如截图,dataGridView1第2列的第一个cell是空的。
我该怎么修改代码才好?

某的主页 | 菜鸟二级 | 园豆:278
提问于:2017-04-08 22:13
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册