0

bindingsource の datagridview には 3 つの列が含まれていますが、そのうちの 1 つには ComboBoxes が含まれています。

以下のコードでxmlファイルに書き込むことができますが、どうすればそれを読み取ることができますか? あなたの助けに感謝

Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, _
                   ByVal e As EventArgs) Handles MyBase.Load
    Me.BindingSource2.DataSource = Me.GetParentTable()
    Me.Column1.DisplayMember = "ParentName"
    Me.Column1.ValueMember = "ParentID"
    Me.Column1.DataSource = Me.BindingSource2
    Me.BindingSource1.DataSource = Me.GetChildTable()
    With DataGridView1
        .DataSource = Me.BindingSource1
        .AllowUserToAddRows = True : .AllowUserToDeleteRows = True
        .AllowUserToOrderColumns = False : .AllowUserToResizeRows = True
    End With
End Sub
Private Function GetParentTable() As DataTable
    Dim table As New DataTable
    With table.Columns
        .Add("ParentID", GetType(Integer))
        .Add("ParentName", GetType(String))
    End With
    With table.Rows
        .Add(1, "Parent 1")
        .Add(2, "Parent 2")
        .Add(3, "Parent 3")
    End With
    Return table
End Function
Private Function GetChildTable() As DataTable
    Dim table As New DataTable ("IOBOARD")
    With table.Columns
        .Add("ChildID", GetType(Integer))
        .Add("ParentID", GetType(Integer))
        .Add("ChildName", GetType(String))
    End With
    With table.Rows
        .Add(1, 3, "Child 1")
        .Add(2, 2, "Child 2")
        .Add(3, 1, "Child 3")
    End With
    Return table
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Save To XML
    Dim dt As DataTable = CType(BindingSource1.DataSource, DataTable)
    dt.AcceptChanges()
    dt.WriteXml("c:\so\Test.xml", System.Data.XmlWriteMode.WriteSchema, False)
End Sub

クラス終了

4

1 に答える 1

0

dataset.ReadXmlメソッドを試しましたか?

于 2013-06-07T20:39:00.743 に答える