Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2004-11-02
Medium Priority
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
  • 2
LVL 25

Accepted Solution

RonaldBiemans earned 1200 total points
ID: 12481044
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

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



Author Comment

ID: 12486020
Hi Ronald,

Thanks for your quick and helpful response.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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…
Suggested Courses

572 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