[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
Thanks in advance
Re: move cursor in selected rows in datagridview
Try this :
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
Me.DataGrid.CurrentCell = DataGridView1.Item(1, x)
Exit Sub
End If
Next
I hope it helps! :)
Re: move cursor in selected rows in datagridview
Quote:
Originally Posted by
HanneSThEGreaT
Try this :
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
Me.DataGrid.CurrentCell = DataGridView1.Item(1, x)
Exit Sub
End If
Next
I hope it helps! :)
Me.DataGridView1.CurrentCell = DataGridView1.Item( DataGridView1.FirstDisplayedCell.ColumnIndex , x)
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)).
Re: move cursor in selected rows in datagridview
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....
Thanks again
Re: move cursor in selected rows in datagridview
Me.Datagrid.CurrentCell = me.Datagrid.Rows(i).Cells(1)
it works fine.... thanks
Re: move cursor in selected rows in datagridview
Glad you came right, good work! :thumb:
And thanx for sharing! :)