Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 470
Peter Avatar asked Apr 08 '13 12:04

Peter


3 Answers

Just put dataGridView1.ClearSelection(); in load event of the form.

like image 153
ramires.cabral Avatar answered Nov 14 '22 00:11

ramires.cabral


This works for me:

private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    dataGridView1.Rows[0].Selected = false;
}
like image 17
Nicolas Tyler Avatar answered Nov 14 '22 00:11

Nicolas Tyler


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 :)

like image 16
Peter Avatar answered Nov 14 '22 01:11

Peter