Remove blue colored row from DataGridView WinForms

后端 未结 5 839
有刺的猬
有刺的猬 2020-12-21 17:09

When I fill a DataGridView row by row (calling it\'s add function), the top row gets blue colored. It\'s not selected because I tried ClearSelection() also but it didnt work

5条回答
  •  被撕碎了的回忆
    2020-12-21 17:37

    I tried the above methods but nothing worked for me.

    Finally, I just decided to set the default colors for selected cells to be the same as non-selected cells.

    Then, in the cell click method, I set them back. That way nothing appears selected until its clicked, which was sufficient for my application. Here's the code I used in the click method to set everything back to normal:

    dataGridView.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
    dataGridView.DefaultCellStyle.SelectionForeColor = SystemColors.Window;
    

    Annoyingly, the ClearSelection method actually works just fine if I put it in a button, but if I create the control which contains the datagrid, load some data into it, and then try to clear it right then, it doesn't work. I wish I knew why...

提交回复
热议问题