DataGridView - Row Selection

alfardan
alfardan used Ask the Experts™
on
Hi

I have a daragrid in a windows application, and when it loads it selects its first row by default, I don't want that, how do I let this datagrid selects no row when it loads?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dirk HaestProject manager

Commented:
after bounding data just call

dataGridView.ClearSelection();

(calling .ClearSelection() from the DataBindingComplete event of the DataGridView itself.)

Author

Commented:
I'm not binding data to the grid, I'm adding rows through a for loop

Commented:
Not sure if this will work, but try setting the currentcell to nothing at the end of the form load event, e.g
Me.DataGridView1.CurrentCell = Nothing

Open in new window

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Author

Commented:
Didn't work, still selects the first row by default

Commented:
Then
Me.DataGridView1.ClearSelection()

Open in new window

and / or setting the tab index for the datagridview to greater than 0 should work

Author

Commented:
Didn't work either

Ok, how do I make the row selection coloring to be of a specific color that I determine  instead of the default BLUE one?
Most Valuable Expert 2012
Top Expert 2014
Commented:
For selection colour, use DefaultCellStyle

dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial