1、场景需求,勾选单元格,获取所有当权选中数据;
先用第一个单元格修改事件,
private void dgvMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
}
发现勾选完,光标移走才触发;
实现方法,两个事件;
初始化列
增加 FalseValue = 0,TrueValue=1,
dgvMain.Columns.Add(new DataGridViewCheckBoxColumn { HeaderText = " ", DataPropertyName = nameof(MdPrintDataFileNameEx.Check), Name = nameof(MdPrintDataFileNameEx.Check), AutoSizeMode = DataGridViewAutoSizeColumnMode.None, FalseValue = 0,TrueValue=1, Width = 30, ReadOnly = false, Frozen = true }); dgvMain.Columns.Add(new DataGridViewTextBoxColumn { HeaderText = "No.", DataPropertyName = nameof(MdPrintDataFileNameEx.No), Name = nameof(MdPrintDataFileNameEx.No), AutoSizeMode = DataGridViewAutoSizeColumnMode.None, Width = 50, ReadOnly = false, Frozen = true });
事件代码
private void dgvMain_CurrentCellDirtyStateChanged(object sender, EventArgs e) { //提交改变,触发dataGridView1_CellValueChanged事件,以便及时获取check的值改变事件 if (dgvMain.IsCurrentCellDirty) { dgvMain.CommitEdit(DataGridViewDataErrorContexts.Commit); } } private void dgvMain_CellValueChanged(object sender, DataGridViewCellEventArgs e) { QueryDtl(); }
标签:MdPrintDataFileNameEx,nameof,private,dgvMain,DGV,事件,选中,DataGridView From: https://www.cnblogs.com/yuanshuo/p/17971120