Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

Databinding issue

$
0
0
I need display parent and child or Master and detail table in two datagrids. The source table is not fixed. In winform, I added two databindings and used below method. However, there is no databindings in WPF. How can I migrated the previous Winform to WPF? (below code has been modified in WPF except for bindingsource1 and bindingsouce2)

Code:


        Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Loaded

        Me.MasterDGV.ItemsSource = Me.BindingSource1
        Me.DetailDGV.ItemsSource = Me.BindingSource2

    End Sub

    Private Sub LoadData()

        Data = Nothing
        Data = New DataSet

        SourcePath = "C:\Quote Kit\Sourcefile\emg_A_US_CN_USD_CIP.xlsx"
        Currency = "USD"

        MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + SourcePath + "; Extended Properties=Excel 12.0;")
        MasterAdapter = New System.Data.OleDb.OleDbDataAdapter("select Partnumber,Option,Description," & Currency & " from [Sheet1$] where partnumber=option", MyConnection)
        DetailAdapter = New System.Data.OleDb.OleDbDataAdapter("select Partnumber,Option,Description," & Currency & " from [Sheet1$] where partnumber<>option", MyConnection)

        MasterAdapter.Fill(Data, "Parent")
        DetailAdapter.Fill(Data, "Child")
        MyConnection.Close()


    End Sub

    'Define Master and Detail binding source
    Public Sub BindingData()

        Try

            Dim Data As DataSet = Me.GetDataSet()

            Me.bindingsource1.datasource = Data
            Me.BindingSource1.DataMember = "Parent"

            Me.BindingSource2.DataSource = Me.BindingSource1
            Me.BindingSource2.DataMember = "ParentChild"

            Me.MasterDGV.ItemsSource = Me.BindingSource1
            Me.DetailDGV.ItemsSource = Me.BindingSource2

        Catch ex As Exception

        End Try

    End Sub

    'Load Data
    Public Function GetDataSet() As DataSet

        LoadData()

        Data.Relations.Add("ParentChild", Data.Tables("Parent").Columns("Partnumber"), Data.Tables("Child").Columns("Partnumber"))

        Return Data

    End Function


Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>