Re: Control dataset synchronization

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Cor Ligthert (notmyfirstname_at_planet.nl)
Date: 10/05/04


Date: Tue, 5 Oct 2004 18:25:09 +0200

Steve,

This is the thirth time today I sent this sample what I made today, can you tell me if it helps you because it is brand new.

Cor

\\\ Needs a form with two datagrids, a button and a label
'The first click on the button shows one datagrid
'The second click shows the same info with two datagrid
'To make it nice a lot of other code is needed by instance datagridtablestyles
'and columnstyles
Private Ds As New DataSet
Private dtCountries As DataTable
Private dtVBLTRegulars As DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
        CreateTables()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Static pushed As Integer = 1
        Select Case pushed
            Case 1
                Label1.Text = "Relation One Datagrid"
                Dim drel As New DataRelation _
                  ("Regulars", Ds.Tables("Countries").Columns("Country"), _
                  Ds.Tables("Persons").Columns("Country"))
                Ds.Relations.Add(drel)
                DataGrid1.DataSource = dtCountries
                DataGrid1.Expand(-1)
            Case 2
                Ds.Relations.RemoveAt(0)
                Label1.Text = "Relation two Datatgrids"
                Dim drel As New DataRelation _
                  ("Regulars", Ds.Tables("Countries").Columns("Country"), _
                   Ds.Tables("Persons").Columns("Country"))
                Ds.Relations.Add(drel)
                DataGrid1.SetDataBinding(Ds, "Countries")
                DataGrid2.SetDataBinding(Ds, "Countries.Regulars")
        End Select
        pushed += 1
End Sub
'This is only needed to show the sample
Private Sub CreateTables()
        dtVBLTRegulars = New DataTable("Persons")
        dtVBLTRegulars.Columns.Add("Id")
        dtVBLTRegulars.Columns.Add("Name")
        dtVBLTRegulars.Columns.Add("Country")
        For i As Integer = 0 To 7
            Dim dr As DataRow = dtVBLTRegulars.NewRow
            dr(0) = i.ToString
            dtVBLTRegulars.Rows.Add(dr)
        Next
        dtVBLTRegulars.Rows(0)(1) = "Herfried K. Wagner"
        dtVBLTRegulars.Rows(1)(1) = "Ken Tucker"
        dtVBLTRegulars.Rows(2)(1) = "CJ Taylor"
        dtVBLTRegulars.Rows(3)(1) = "Jay B Harlow"
        dtVBLTRegulars.Rows(4)(1) = "Terry Burns"
        dtVBLTRegulars.Rows(5)(1) = "Tom Shelton"
        dtVBLTRegulars.Rows(6)(1) = "Cor Ligthert"
        dtVBLTRegulars.Rows(0)(2) = "EU"
        dtVBLTRegulars.Rows(1)(2) = "US"
        dtVBLTRegulars.Rows(2)(2) = "US"
        dtVBLTRegulars.Rows(3)(2) = "US"
        dtVBLTRegulars.Rows(4)(2) = "EU"
        dtVBLTRegulars.Rows(5)(2) = "US"
        dtVBLTRegulars.Rows(6)(2) = "EU"
        dtCountries = New DataTable("Countries")
        dtCountries.Columns.Add("Id")
        dtCountries.Columns.Add("Country")
        For i As Integer = 0 To 1
            Dim dr As DataRow = dtCountries.NewRow
            dr(0) = i.ToString
            dtCountries.Rows.Add(dr)
        Next
        dtCountries.Rows(0)(1) = "EU"
        dtCountries.Rows(1)(1) = "US"
        Ds.Tables.Add(dtVBLTRegulars)
        Ds.Tables.Add(dtCountries)
End Sub
///


Quantcast