Navigating a DataGrid

I have a WinForm with a TabControl on it with 2 Tabs. One for list (where I have my DataGrid - dg) and the other one for details. When I navigate through my DataGrid (either through my keyboard or by clicking a mouse on a row), the details Tab should show the currently selected row. Also, I want to hilight the entire row selected and not just the cell. How would I do it  What are the Events I would trap  An example would help.

Answer this question

Navigating a DataGrid

  • Takteek

    Just trying to figure out what you want. Wouldn't the details tab show more then one row normally

    What do you mean to highlight the entire row  are we talking about highligting the row on the parent datagrid or the child datagrid.

    For parent child relationships you should do this

    Create a relation object between the two datatables in your dataset

    set the parent datagrid to the parent datatble

    datagrid1.datasource = mydataset
    datagrid1.datamember = "MyDatatable"

    Now set the child datagrid to the relation

    datagrid2.datasource = Mydataset
    datagrid2.datamember = "MyDatatable.RelationName"

    So as you move around in datagrid 1, it will only show records related to the currently selected row in the parent inside of datagrid 2 (the child/details). 

    Hope this helps, also there is some info at:
    http://www.syncfusion.com/FAQ/WinForms/default.asp#44

  • Mayil

    I'm curious what the solution to the original question is because I am doing the exact same thing with a datagrid and tab controls.   I have a form with a tab control on it with 2 tabs.  The first tab is a search that populates a datagrid.  I would like to be able to select a row in the datagrid by either double clicking or using a context menu (with edit and delete options) which would then navigate to the second tab which is a detail of the record.  I checked out your site suggestion and wasn't able to find an example of this issue.  Were you able to provide the original person an example of this code   Thank you in advance for your help.
  • Dave Cliffe - MSFT

    I just have one datagrid and do not have any parent-child relations. When I move from cell to cell by keyboard(and not by mouse), the curren cell gets highlighted. I want the entire row to be highlighted instead of the current cell getting highlighted. Hope this clarifies.
  • andhowdy

    I was not able to sind a solution for keyboard navigation but for mouse navigation I implemented the following code:

        Private Sub dg1_MouseUpDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dg1.MouseUp, dg1.MouseDown
            Dim hitInfo As System.Windows.Forms.DataGrid.HitTestInfo
            hitInfo = dg1.HitTest(e.x, e.Y)
            If hitInfo.Type = System.Windows.Forms.DataGrid.HitTestType.Cell Then
                'Changed the cursor to waitCursor
                Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
                Me.SuspendLayout()
                Me.tcQueryResult.SelectedIndex = 0
                Me.ResumeLayout()
                'Reset the cursor
                Me.Cursor = System.Windows.Forms.Cursors.Default
            End If
        End Sub

  • leoxtc

    Hope this helps, also there is some info at: 
    http://www.syncfusion.com/FAQ/WinForms/default.asp#44

  • Navigating a DataGrid