Search code examples
c#.netwinformsdatagridview

DataGridView without selected row at the beginning


In my WinForms I have DataGridView. I wanted to select full row at once so I set SelectionMode as FullRowSelect. And now I have problem, because at the beginning my form underlines first row (set of selected rows is empty, the first row is not selected but just underlined). I have tried many things, such as:

    private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        dataGridView1.ClearSelection();
    }

And all failed, because in fact there is no selection.

How can I get rid of this underline?

Thanks for any help!


Solution

  • Unfortunately none of these answers helped me, but I found other solution. Instead of unable selection I will just hide it with this piece of code:

    dataGridView1.DefaultCellStyle.SelectionBackColor = dataGridView1.DefaultCellStyle.BackColor;
    dataGridView1.DefaultCellStyle.SelectionForeColor = dataGridView1.DefaultCellStyle.ForeColor;
    

    So if anyone just wants to hide the selection it's gonna work pretty well.

    Cheers :)