Why didn't trigger the CellEndEdit event of DataGridView

后端 未结 3 1852
遇见更好的自我
遇见更好的自我 2021-01-22 20:25

All,I knew we can set a column editable for a DataGridView. And when finish editing the cell. the CellEndEdit event would be triggered. But I just want

3条回答
  •  走了就别回头了
    2021-01-22 21:04

    Try using the HitTest function in the MouseDown event of the grid:

    void dgvFileList_MouseDown(object sender, MouseEventArgs e) {
      DataGridView.HitTestInfo hit = dgvFileList.HitTest(e.X, e.Y);
      if (hit.RowIndex < 0 | hit.ColumnIndex < 0) {
        dgvFileList.EndEdit();
      }
    }
    

    Clicking outside the DataGridView control would require hitting a focusable control.

提交回复
热议问题