-
June 2nd, 2009, 04:08 AM
#1
[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
-
June 2nd, 2009, 09:50 AM
#2
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!
-
June 2nd, 2009, 11:26 PM
#3
Re: move cursor in selected rows in datagridview
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)).
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
- ComIT Solutions
-
June 3rd, 2009, 04:05 AM
#4
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
-
June 3rd, 2009, 07:48 PM
#5
Re: move cursor in selected rows in datagridview
Me.Datagrid.CurrentCell = me.Datagrid.Rows(i).Cells(1)
it works fine.... thanks
-
June 4th, 2009, 01:51 AM
#6
Re: move cursor in selected rows in datagridview
Glad you came right, good work!
And thanx for sharing!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|