[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to focus selected row in a datagrid?

Posted on 2005-04-28
7
Medium Priority
?
1,185 Views
Last Modified: 2012-08-13
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
Comment
Question by:tikusbalap
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:checoo
ID: 13892607
use
datagrid1.focus()
followed by
datagrid1.setselected(i,true)
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 13895296
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
 
LVL 6

Author Comment

by:tikusbalap
ID: 13907869
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Accepted Solution

by:
checoo earned 500 total points
ID: 13908145
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
 
LVL 6

Author Comment

by:tikusbalap
ID: 13915275
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
 
LVL 9

Expert Comment

by:checoo
ID: 13915307
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
 
LVL 6

Author Comment

by:tikusbalap
ID: 13916321
Ok.Thx!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question