Remove blue colored row from DataGridView WinForms

后端 未结 5 831
有刺的猬
有刺的猬 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:39

    After three hours of troubleshooting this, I've figured it out: Your DataGridView needs to be displayed on the screen before calling dataGridView.ClearSelection().

    How I know this works:

    I have two DataGridViews, each in a different panel. Only one panel is visible at a time. In the panel that's initially visible, the DataGridView has never ignored my call to ClearSelection(), so I've never seen a row selected right away.

    I used to populate the other DataGridView and clear its selection before showing the panel that contains it, but that top row was always still highlighted. I changed my code to display the other panel before clearing the DataGridView's selection, and the call to ClearSelection() worked as it should.

提交回复
热议问题