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++;
}
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是空的。
我该怎么修改代码才好?