Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When you add items to the DataGridView1 it will automatically select the 1st row, even if you use DataGridView1.ClearSelection afterwards, the 1st row is still selected!

However, my problem is that if you use ::

 

DataGridView1.ClearSelection()

DataGridView1.Rows.Item(2).Selected = True

DataGridView1.FirstDisplayedScrollingRowIndex = 2

 

Still the 1st row is selected! :confused:

Anyone knows about it?

WindowsApplication1.zip

  • 2 weeks later...
Posted

I have always turned the row headers off, so I don't know what that funky looking mouse glyph is all about.

 

However, in the code above, it works better if you'll comment out the 'ClearSelection()' line.

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   'DataGridView1.ClearSelection()
   For Each row As DataGridViewRow In DataGridView1.Rows
     If (row.Selected) Then
       Console.WriteLine("Row {0} was selected", row.Index + 1)
       row.Selected = False
     End If
   Next
   DataGridView1.Rows.Item(2).Selected = True
   'DataGridView1.FirstDisplayedScrollingRowIndex = 2
   For Each row As DataGridViewRow In DataGridView1.Rows
     If (row.Selected) Then
       Console.WriteLine("Row {0} now selected", row.Index + 1)
     End If
   Next
 End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...