+ Reply to Thread
Results 1 to 4 of 4

Thread: DataGridView Like Microsoft Access Child/Detail

  1. #1
    daPoet is offline VB.NET Forum Newbie daPoet is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2008
    Age
    26
    Posts
    23
    Reputation
    27

    Wink DataGridView Like Microsoft Access Child/Detail

    How do I create a Master Detail Form with DataGridView

    For anyone else looking for a way to use DataGridView in the same way it would appear in Microsoft Access, This is what I've come up with just as a guide..


    From what I've been reading, the closest thing that can be used in .NET to do this is ASP.NET since its more likely to be done as a web component..

    So what I'm going to do is this. Using One DataGridView on my Main Form, I'm going to use code to resize the Row Size when I've clicked on a particular row. i.e. Make the Row Get Taller/Longer,


    Then use code to place another DataGridView, "the child" inside of a panel that is minimised and hidden on my Master Form.
    This Child DataGridView inside of the Second Panel, will then be placed withing the Space of the Heightened Row that was selected..

    I'll post the Code fragments when I'm done so far Im gona test this code for the row resizing
    Code:
     Private Sub DataGridView1_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
            If e.RowIndex > -1 Then
                DataGridView1.Rows(e.RowIndex).Height = 35
            End If
    End Sub

  2. #2
    daPoet is offline VB.NET Forum Newbie daPoet is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2008
    Age
    26
    Posts
    23
    Reputation
    27

    Default

    Code:
       Private Sub dataGridView1_RowHeaderMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles Tbl_DptDataGridView.RowHeaderMouseClick
            Me.Tbl_DptDataGridView.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
            If Me.Tbl_DptDataGridView.Rows(e.RowIndex).Selected = True Then
                Tbl_DptDataGridView.Rows(e.RowIndex).Height = 80
            End If
        End Sub
    This code resizes the row height when that row is selected. ;-)
    1. The next part of the problem is to return its size to the default when another cell is selected
    2. Also when the row's height increase I need to get the contents to be positioned at the top of that cell

    When I've solved, I'll post

  3. #3
    daPoet is offline VB.NET Forum Newbie daPoet is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2008
    Age
    26
    Posts
    23
    Reputation
    27

    Default

    Okay, so of the last two problems I've said I had, this is what I've done to correct the formatting of the cell contents in the cell problem


    I used this code
    Code:
    Me.Tbl_DptDataGridView.Rows(e.RowIndex).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
    So at least I dont have to worry that the content's of the row will be hidden behind my second panel with the child data grid when I place it in that row space

  4. #4
    daPoet is offline VB.NET Forum Newbie daPoet is on a distinguished programming path ahead
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jul 2008
    Age
    26
    Posts
    23
    Reputation
    27

    Default

    Okay so the code may need tiding up, maybe someparts in the If syntax may even be redundant but this is what I have and so far it works like a charm for what I wana do.

    Im gona do this with a 4 tier table link up structure, so the first Grid is going to be in the biggest panel, the second in the second biggest, the third in the third biggest etc

    The first grid-row will see the second grid appearing as though it is "nested" within the expanded row etc

    You will need to modify the code to get the panel to dynamically appear lower and lower depending on which row is selected as you go down the records in your Grid,

    OR

    You will need to autoscroll the selected record you've clicked in the parent grid to the Top of that Grid, that way you wouldnt need to move the Child grids ,,,

    Hope this helps someone

    I'll post the final thing with an example when its totally done, but again, I still dont know how to export a project lol

    Code:
    Private Sub dataGridView1_RowHeaderMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles Tbl_DptDataGridView.RowHeaderMouseClick
            Me.Tbl_DptDataGridView.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
            Me.txt_Flag.Text = ""
            If Me.Tbl_DptDataGridView.Rows(e.RowIndex).Selected = True Then
                If Me.Tbl_DptDataGridView.Rows(e.RowIndex).Height <> 300 Then
                    Tbl_DptDataGridView.Rows(e.RowIndex).Height = 300
                    Me.Tbl_DptDataGridView.Rows(e.RowIndex).DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
                    Me.Panel2.Location = New Point((Panel1.Location.X + 50), (Panel1.Location.Y + 50))
                    Me.Panel2.Visible = True
                Else
                    Tbl_DptDataGridView.Rows(e.RowIndex).Height = 20
                    Me.Panel2.Visible = False
                End If
            Else
    
            End If
    
    
        End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts