【发布时间】:2014-08-02 08:49:10
【问题描述】:
我有一个 dataGridView,其中包含第一列中的复选框。现在,根据我的要求,我必须获取在另一个按钮单击事件上单击其复选框的行的 Employee No 列的值。此外,如何获取选中的多个复选框的值。
这是我的代码..
private void btn_load_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Select", System.Type.GetType("System.Boolean"));
dt.Columns.Add("Employee No");
dt.Columns.Add("Employee Name");
dt.Columns.Add("Join Date");
DataRow dr;
for (int i = 0; i <= 10; i++)
{
dr = dt.NewRow();
dr["Select"] = false;
dr["Employee No"] = 1000 + i;
dr["Employee Name"] = "Employee " + i;
dr["Join Date"] = DateTime.Now.ToString("dd/MM/yyyy");
dt.Rows.Add(dr);
}
dataGridView1.AllowUserToAddRows = true;
dataGridView1.AllowUserToDeleteRows = true;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.DataSource = dt;
}
private void btn_Click(object sender, EventArgs e)
{
//I need the Employee Id values here
}
请帮助我。在此先感谢..
【问题讨论】:
-
使用DataGridView_CellContentClick事件捕获Employee Id值
-
私有子 DataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) 处理 DataGridView.CellContentClick If DataGridView.Rows(DataGridView.CurrentCell.RowIndex).Cells(0) .Value = True Then '做某事 End If End Sub
标签: c# winforms checkbox datagridview