Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms - DataGridView - no cell selected

Is there a way to make a DataGridView have no cell selected? I notice even when it loses focus() it has a at least one active cell. Is there another mode that allows this? or some other trick?

like image 577
BuddyJoe Avatar asked Dec 04 '08 15:12

BuddyJoe


2 Answers

DataGridView.CurrentCell property can be used to clear the focus rectangle.

You can set this property (DataGridView.CurrentCell) to null to temporarily remove the focus rectangle, but when the control receives focus and the value of this property is null, it is automatically set to the value of the FirstDisplayedCell property.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcell.aspx

like image 52
Aleris Avatar answered Sep 19 '22 17:09

Aleris


The problem with setting the DataGridView.CurrentCell to null on the selection change event is that later events (like click) will not be hit.

The option that worked for me was to change the selection color to the grid color. The selection will therefore not be visible.

RowsDefaultCellStyle.SelectionBackColor = BackgroundColor;
RowsDefaultCellStyle.SelectionForeColor = ForeColor;
like image 39
J. Ouwehand Avatar answered Sep 18 '22 17:09

J. Ouwehand