How to deselect all selected rows in a DataGridView control?

前端 未结 6 694
臣服心动
臣服心动 2021-01-31 01:24

I\'d like to deselect all selected rows in a DataGridView control when the user clicks on a blank (non-row) part of the control.
How can I do this?

6条回答
  •  不要未来只要你来
    2021-01-31 02:14

    Thanks Cody heres the c# for ref:

    if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                DataGridView.HitTestInfo hit = dgv_track.HitTest(e.X, e.Y);
                if (hit.Type == DataGridViewHitTestType.None)
                {
                    dgv_track.ClearSelection();
                    dgv_track.CurrentCell = null;
                }
            }
    

提交回复
热议问题