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

Posted on 2004-11-02
Last Modified: 2010-04-24
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!

Question by:mdenington
    LVL 25

    Accepted Solution

    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
            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
            If DataGrid1.DataMember = "Relations" Then
            ElseIf DataGrid1.DataMember = "Projects" Then
            End If
        End Sub

        Private Sub formatDatagridrel()
            Dim dg As New DataGridTableStyle
            dg.MappingName = "Relations"

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

        End Sub

        Private Sub formatDatagridpro()
            Dim dg As New DataGridTableStyle
            dg.MappingName = "Projects"

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

        End Sub
    LVL 25

    Expert Comment

    Sorry , I forgot to remove this line. (It was just for testing my solution)



    Author Comment

    Hi Ronald,

    Thanks for your quick and helpful response.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now