Not to select the first row in DataGridView by default

14 May

DataGridView makes the first row selected after DataBinding by default. I tried using DataGridView.ClearSelection() in the Form.Load event to unselect it with no avail. The problem is that data hasn’t been bond to the DataGridView in the Form.Load event. The method should be placed in the DataBindingComplete event of the DataGridView:

Private Sub DataGridView1_DataBindingComplete(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) _
    Handles DataGridView1.DataBindingComplete

    Dim gridView As DataGridView
    gridView = CType(sender, DataGridView)
End Sub

Reference: C# DataGridView: First row is being selected by default


Posted by on May 14, 2012 in .NET, VB, Winform



11 responses to “Not to select the first row in DataGridView by default

  1. Gus Sampaio

    October 8, 2012 at 11:46 AM

    After checking many forums and websites with different solutions, your code was the only one that really worked for me.
    Thanks a lot.

  2. Brian

    January 4, 2013 at 11:52 PM

    Big Help!!!

  3. Dave

    March 12, 2013 at 8:10 PM

    Helped Me thanks, only solution thats claers selection, obviously the databind takes longer than the formload event to trigger.

  4. Fabrício Henriques

    June 16, 2013 at 4:29 AM

    Nice job

  5. Fedel Petallo Magbanua

    October 17, 2013 at 4:17 PM

    tnx big help..

  6. shrikant

    December 14, 2013 at 10:45 PM

    thanks a lot ,
    It worked for me .

  7. Waqas

    December 24, 2013 at 4:25 AM

    Yes it did work for me as well, Thanks a lot and well done!!!!

  8. Souvik Das

    June 20, 2014 at 10:34 AM

    A Big Thanks. Only thing I found in Internet that actually worked.

  9. Alex

    August 29, 2014 at 11:01 PM

    Selection disabled, but SelectionChanged event still triggered…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: