Hallo Zusammen!
Ich möchte Daten aus einer XML - Datei in ein DataGridView einlesen.
Das funktioniert soweit auch schon, wenn ich mein Programm starte und nur einen Datesatz einlese.
Private XML_File As String = "C:\Users\....\VKR_Profiluebersicht.xml"
Private ds As New DataSet
Private dt As System.Data.DataTable
Private bs As New BindingSource
Private WithEvents dv As DataView
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles _
Button2.Click
ds.Clear()
ds.ReadXml(XML_File)
End Sub
Public Sub New()
InitializeComponent()
Dim dt As New System.Data.DataTable("Rechteckrohr")
ds.Tables.Add(dt)
Dim col0 As System.Data.DataColumn = dt.Columns.Add("Bezeichnung", GetType( _
System.String))
col0.DefaultValue = String.Empty
'... folgend MB, MH und MW
DGV1.DataSource = ds
DGV1.DataMember = ds.Tables(0).TableName
FormatDGV1(DGV1)
End Sub
Private Sub FormatDGV1(ByVal DGV As DataGridView)
With DGV
.DefaultCellStyle.Alignment = _
DataGridViewContentAlignment.MiddleLeft
.ColumnHeadersHeightSizeMode = _
DataGridViewColumnHeadersHeightSizeMode.DisableResizing
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken
.ColumnHeadersDefaultCellStyle.BackColor = Drawing.Color.Aqua
.ColumnHeadersHeight = 24
.ColumnHeadersDefaultCellStyle.Font = New Drawing.Font("Arial", 8)
.RowHeadersVisible = False
.DefaultCellStyle.WrapMode = DataGridViewTriState.False
.DefaultCellStyle.NullValue = ""
.RowsDefaultCellStyle.BackColor = Drawing.Color.White
.AlternatingRowsDefaultCellStyle.BackColor = Drawing.Color.Beige
.RowsDefaultCellStyle.Font = New Drawing.Font("Arial", 8)
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToResizeColumns = False
.AllowUserToResizeRows = False
.ReadOnly = True
End With
' Datum formatieren:
DGV.Columns.Remove("Bezeichnung")
Dim tbc1 As New DataGridViewTextBoxColumn()
tbc1.DataPropertyName = "Bezeichnung"
tbc1.HeaderText = "Bezeichnung"
tbc1.Width = 195
tbc1.DefaultCellStyle.Alignment = _
DataGridViewContentAlignment.MiddleLeft
tbc1.DisplayIndex = 0
DGV.Columns.Add(tbc1)
'... folgend MB, MH und MW
End Sub
Private Sub BindControls()
bs.DataSource = dt
Me.TB_MB.DataBindings.Add(New Binding("Text", bs, "MB", True))
Me.TB_MH.DataBindings.Add(New Binding("Text", bs, "MH", True))
Me.TB_MW.DataBindings.Add(New Binding("Text", bs, "MW", True))
DGV1.DataSource = bs
DGV1.ReadOnly = True
DGV1.AllowUserToAddRows = False
DGV1.AllowUserToDeleteRows = False
End Sub Nun möchte ich aber zwischen den Varianten "Quadratrohr" und "Rechteckrohr" mittels RadioButton
filtern können.
<?xml version="1.0" standalone="yes" ?>
<DockumentElement>
<Quadratrohr>
<Bezeichnung>10 x 10 x 1,50</Bezeichnung>
<MB>10</MB>
<MH>10</MH>
<MW>1.5</MW>
</Quadratrohr>
<Rechteckrohr>
<Bezeichnung>15 x 10 x 1,50</Bezeichnung>
<MB>15</MB>
<MH>10</MH>
<MW>1.5</MW>
</Rechteckrohr>
'... Ansatz war so, funktioniert aber nicht.
Public Sub New()
If RB_QROHR.Checked = True Then
InitializeComponent()
Dim dt As New System.Data.DataTable("Quadratrohr")
ds.Tables.Add(dt)
ElseIf RB_RROHR.Checked = True Then
InitializeComponent()
Dim dt As New System.Data.DataTable("Rechteckrohr")
ds.Tables.Add(dt)
End If
Dim col0 As System.Data.DataColumn = dt.Columns.Add("Bezeichnung", _
GetType(System.String))
col0.DefaultValue = String.Empty
Dim col1 As System.Data.DataColumn = dt.Columns.Add("MB", GetType( _
System.String))
col1.DefaultValue = String.Empty
Dim col2 As System.Data.DataColumn = dt.Columns.Add("MH", GetType( _
System.String))
col2.DefaultValue = String.Empty
Dim col3 As System.Data.DataColumn = dt.Columns.Add("MW", GetType( _
System.String))
col3.DefaultValue = String.Empty
DGV1.DataSource = ds
DGV1.DataMember = ds.Tables(0).TableName
FormatDGV1(DGV1)
End Sub Wenn ich zwischen den RadioButton hin und her schalte, so soll die entsprechende Liste bzw. Daten
geladen werden.
Das bekomme ich aber nicht hin. Kann mir dabei jemand weiterhelfen!?
Vielen Dank im Voraus.
VG
Dirk |