Hi Experts
i m using these code for selecting data grid row

While i <= DataGridView1.Rows.Count - 1
            If Trim(DataGridView1.Rows(i).Cells(0).Value) = Trim(TextBox1.Text) Then
                DataGridView1.Rows(i).Selected = True
                Exit While
            End If
            i = i + 1
        End While

it's working nice.
but , when no of row more then grid showing rows then grid not show selected row in grid screen, for showing selected row we have to use scroll bar,
my problem is how to show selected row in grid automatically

Recommended Answers

All 2 Replies

After

DataGridView1.Rows(i).Selected = True

Add code

DataGridView1.CurrentRowIndex = i

This will select the row in the grid and automatically scroll to the row...
See if this works....

Above is true for VS2003.. For VS2005 you need to select a visible cell in the desired row...

DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(0)

This will make the scroll to the "i" th row and Cell(0) will be selected. If you wish to display the whole row selected then after above code do

DataGridView1.Rows(i).Selected = True

now the "i"th row will be scrolled and selected.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.