none
Restricting cell selection in DGV RRS feed

  • Question

  • From what I have observed, the first non-empty row is highlighted by default.  I'm choosing CellSelect for SelectionMode.  Is there any way of restricting cell selection to the first (left-most) column only?
    Monday, September 9, 2019 12:57 PM

All replies

  • Hi,

    >> From what I have observed, the first non-empty row is highlighted by default

    I don't quite understand this sentence. In my test, the highlight area is the 1st one in the first row which is not empty. Therefore, could you please explain it?

    As to "restricting cell selection to the first (left-most) column only", you can achieve it by judging the selected cell's columnindex. And the following is a simple demo you can refer to.

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != 0)
            {
                dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = false;
                dataGridView1.Rows[e.RowIndex].Cells[0].Selected = true;
            }
        }

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 10, 2019 9:03 AM
    Moderator