Changing the DatagridTableStyle when switching to a Parent or Child Table in a DataGrid

I have figured out how to format a single table in a Datagrid control by formatting the individual columns and added them to a DatagridTableStyle.

What I would like to do now is setup 2 DatagridTableStyles.  One for a parent table and the other for a child table included in a DataSet.

The datagrid initially loads the parent table and I can apply the DatagridTableStyle for this table.  When you click on the "+" sign which is beside each row in the parent table it shows the "DataRelation" name as a "hotlink" which you can click on to load the associated child records from the Child Table.

Does clicking on the "DataRelation" hotlink raise an event that I use to change the formatting to the DatagridTableStyle for the Child table rows that will be loaded?

When the Child Table Rows are loaded there is an "arrow" in the DataGrid caption area that allows you to navigate back to the parent rows.  Can I capture this event so I can then change the formatting back to the DatagridTableStyle for the parent table.

I really like this feature of the Datagrid control that allows you to view child rows associated with a parent row and I can see how it can be very useful in applications if I can handle the formatting issue.

Any help would be appreciated.  Thanks!

mdeningtonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RonaldBiemansCommented:
Hi Mdenington,

Yes you can, you can use the navigate event of the datagrid, something like this

Private Sub Form18_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SqlDataAdapter2.Fill(DataSet41)
        SqlDataAdapter1.Fill(DataSet41)
        DataGrid1.DataSource = DataSet41
        DataGrid1.DataMember = "Relations"
    End Sub

    Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate
        MsgBox(DataGrid1.DataMember)
        If DataGrid1.DataMember = "Relations" Then
            formatDatagridrel()
        ElseIf DataGrid1.DataMember = "Projects" Then
            formatDatagridpro()
        End If
    End Sub

    Private Sub formatDatagridrel()
        DataGrid1.TableStyles.Clear()
        Dim dg As New DataGridTableStyle
        dg.MappingName = "Relations"
        DataGrid1.TableStyles.Add(dg)

        DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 10
        DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 10

    End Sub

    Private Sub formatDatagridpro()
        DataGrid1.TableStyles.Clear()
        Dim dg As New DataGridTableStyle
        dg.MappingName = "Projects"
        DataGrid1.TableStyles.Add(dg)

        DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 400
        DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 400

    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RonaldBiemansCommented:
Sorry , I forgot to remove this line. (It was just for testing my solution)

MsgBox(DataGrid1.DataMember)


0
mdeningtonAuthor Commented:
Hi Ronald,

Thanks for your quick and helpful response.

Matt
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.