Question Combobox xml data into datagridview

firehuman

Member
Joined
Jun 4, 2013
Messages
8
Programming Experience
1-3
Hi there,

I have this xml file, i want to store only the 2nd panel which is fontstyle B, fontsize 13 and location 100,100. I have a combobox which contain collection "Panel". When selecting 'Panel' in the combobox, then i have to click on the button 'Load to DGV' which pop out a new form where is has a combo box, and a button. The combo box in the new form, as the information of the xml and the button in new form is to add into the datagridview. So the problem now is that, I can't find a way to add my selected xml value into DataGridView. (Note: 2 Form)

Here's my xml file:

VB.NET:
<programsetting>
<panel>
    <fontstyle>A</fontstyle>
    <fontsize>13</fontsize>
    <location>100,100</location>
  </panel>
  <panel>
    <fontstyle>B</fontstyle>
    <fontsize>12</fontsize>
    <location>100,100</location>
  </panel>
  <test>
    <fontstyle>Test1</fontstyle>
    <fontsize>512512512</fontsize>
    <location>100,100</location>
  </test>
  <test>
    <fontstyle>Test2</fontstyle>
    <fontsize>12312312</fontsize>
    <location>100,100</location>
  </test>
</programsetting>


Coding: Form 1
VB.NET:
Imports System.ConfigurationImports System.Xml
Imports System.IO
Imports System.Xml.XPath


Public Class MainForm
    Dim filepath As String
    Dim ds As New DataSet
    Dim doc As New XmlDocument()
    Dim dt As New DataTable

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ComboBox1.SelectedItem = "Panel" Then
            Form2.Show()
            doc.Load("mySetting.xml")
            Dim nameList As XmlNodeList = doc.SelectNodes("/programsetting/panel")
            For Each name As XmlNode In nameList
                Form2.ComboBox1.Items.Add(name.InnerXml)
            Next
        ElseIf ComboBox1.Text = "Test" Then
            Form2.Show()
            doc.Load("mySetting.xml")
            Dim nameList As XmlNodeList = doc.SelectNodes("/programsetting/test")
            For Each name As XmlNode In nameList
                Form2.ComboBox1.Items.Add(name.InnerXml)
            Next
        End If
    End Sub

Button 1: 'Load to DGV'

Coding: Form 2
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        
        Dim col As New DataGridViewColumn
        Dim colsize As New DataGridViewColumn
        Dim colloc As New DataGridViewColumn
        Dim dgvRow As New DataGridViewRow

        MainForm.dgv.Rows.Clear()
        MainForm.dgv.Columns.Clear()


        col.Name = ("fontstyle")
        MainForm.dgv.Columns.Add(col)


        colsize.Name = ("fontsize")
        MainForm.dgv.Columns.Add(colsize)


        colloc.Name = ("location")
        MainForm.dgv.Columns.Add(colloc)
Button1: 'Add into DataGridView' (But I haven't add in the code as I do not know how).

So just need a solution to get 1 of the 'PANEL' from the xml file and store it into the datagridview in form 1.

Untitled.jpg
Step 4: Select one of the data in xml file*

THANK YOU!!
 
Last edited:
Back
Top