[RESOLVED] move cursor in selected rows in datagridview
how can i move the cursor of the datagridview on the selected rows on datagridview.
i used this code and it highlight the rows which matches to txtSearch but the cursor did not move in the selected rows.
Code:
For x As Integer = 0 To Me.Datagrid.Rows.Count - 1
If UCase(Me.Datagrid.Item(1, x).Value.ToString) = Trim(Me.txtSearch.Text) Then
Me.Datagrid.Rows(i).Selected = True
Exit Sub
End If
Next
For x As Integer = 0 To Me.Datagrid.Rows.Count - 1
If UCase(Me.Datagrid.Item(1, x).Value.ToString) = Trim(Me.txtSearch.Text) Then
Me.Datagrid.Rows(i).Selected = True
Me.DataGrid.CurrentCell = DataGridView1.Item(1, x)
Exit Sub
End If
Next
For x As Integer = 0 To Me.Datagrid.Rows.Count - 1
If UCase(Me.Datagrid.Item(1, x).Value.ToString) = Trim(Me.txtSearch.Text) Then
Me.Datagrid.Rows(i).Selected = True
Me.DataGrid.CurrentCell = DataGridView1.Item(1, x)
Exit Sub
End If
Next
to avoid Current cell cannot be set to an invisible cell. error. Which is expected when DataGridView1.columns(1).visible=false.
It is better to check DataGridView1.rows(x).visible along with text search condition
UCase(Me.Datagridview1.Item(1, x).Value.ToString) = Ucase(Trim(Me.txtSearch.Text)).
Last edited by ComITSolutions; June 2nd, 2009 at 11:41 PM.
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
Thanks guys, It works perfectly... How about when I search for a record that is placed in the bottom of the datagrid, it will automatically move there so that the user will not scroll the datagrid just to find the highlighted row....
Bookmarks