DataGridView Problem

usvpn

Freshman
Joined
Apr 19, 2010
Messages
45
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?
 

Attachments

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.
Visual Basic:
  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
 
Back
Top