• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1187
  • Last Modified:

How to focus selected row in a datagrid?

I try to select a row in my datagrid that contain lots row then operator can see what i had selected. I succeed to select with datagrid1.setselected(i,true) but the problem is mydatagrid is not focus to the row which i selected before.

Stupid question maybe :p, but it made me crazy!!
0
tikusbalap
Asked:
tikusbalap
  • 3
  • 3
1 Solution
 
checooCommented:
use
datagrid1.focus()
followed by
datagrid1.setselected(i,true)
0
 
iboutchkineCommented:
Select row when click on a cell
There is not a direct way to set the selection mode directly. You may work
around it by calling the DataGrid.Select method in the MouseUp event
handler. This is a sample code at below:


Private Sub dg_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dg.MouseUp
        Dim pt = New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dg.HitTest(pt)

        If hti.Type = DataGrid.HitTestType.Cell Then
            dg.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dg.Select(hti.Row)
        End If
End Sub


can do the same on mouse down

=============================
also

Private Sub dgList_RowChanging(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dglist.CurrentCellChanged

dglist.Select(dglist.CurrentCell.RowNumber)
0
 
tikusbalapAuthor Commented:
I add a row in my datagrid programatically, then when i repeat this step until the row is exceed the datagrid's height, my last row that i was add last is not seen.

===================== datagrid upper limit height
----------
----------
===================== datagrid lower limit height
----------
----------
0000000  -> i select this row but i can't see it

It's not depend on my mouse

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
checooCommented:
The DataGrid has a protected GridVScrolled member that can be used to scroll the grid. To use it, you can derive from DataGrid and add a ScrollToRow method. Here is a code snippet.
 
     Public Class MyDataGrid
 
      Inherits DataGrid
 
          Sub ScrollToRow(ByVal row As Integer)
 
               If Not Me.DataSource Is Nothing Then
 
                    Me.GridVScrolled(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
 
               End If
 
          End Sub
 
     End Class
 
0
 
tikusbalapAuthor Commented:
Wew..that's works.

But how i create component with that new datagrid to put it to my tool box? create .dll?
Please help me show the step to create that .dll or component?

Thx
0
 
checooCommented:
Create the component in a seperate project and build it as a DLL or exe (doesnt matter which ever you choose). Then right click on the toolbox and select add / remove items, then click on browse and then select your dll / exe and then click "OK". The new item will be added to the toolbox. For creating custom icons for your toolbox items check MSDN help.
0
 
tikusbalapAuthor Commented:
Ok.Thx!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now