从Gridview获取数据到Checkbox

时间:2013-05-31 10:07:26

标签: c# .net winforms

我在c#中制作一个Windows应用程序 并且我想在gridview单元格点击上检查从gridview到checklist框的值,并且已在复选框中选中了值 帮助我,我不知道该怎么做..

1 个答案:

答案 0 :(得分:0)

试试这个,

private void yourGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (yourGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
 yourCheckListBox.Items.Add(yourGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}
}

您可以参考如何将数据添加到checkBoxList HERE

或试试这个,

   private void yourGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (yourGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
 string selectedValue =yourGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
 yourCheckListBox.Items.Add(new BindingList<Binder> { new Binder { Name = selectedValue } });
yourCheckListBox.Invalidate();  
yourCheckListBox.Update();  
yourCheckListBox.Refresh();
}
}
相关问题