disasterkid
disasterkid

Reputation: 7278

DataGridView backcolor of the first row is white although the selection backcolor is transparent

I would like to hide the selection option of my DataGridView so that it seems always like nothing has been selected.

I have set the SelectionBackColor property of my DataGridView to Transparent. But when it loads, the first row's back color is always white although it turns transparent as I select other rows. But at the beginning it is always white.

This is how it looks after loading:

enter image description here

And this is how it looks as I click on another row:

enter image description here

How can I make it so that it always looks like the second picture?

Upvotes: 0

Views: 457

Answers (1)

SSS
SSS

Reputation: 5403

Just deselect the first row after you've filled the grid. By default the first row is selected when you fill it, but it is possible to have no rows at all selected.

DataTable dtb = new DataTable("D");
dtb.Columns.Add("C1");
dtb.Rows.Add("A");
dtb.Rows.Add("B");
dtb.Rows.Add("C");
dtb.Rows.Add("D");
dtb.Rows.Add("E");
dataGridView1.DataSource = dtb;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
if (dataGridView1.SelectedRows.Count > 0)
{
    dataGridView1.Rows[0].Selected = false;
}

Upvotes: 1

Related Questions