Question Using PropertyGrid with XML

LaKirk

New member
Joined
Jun 25, 2013
Messages
4
Programming Experience
10+
I have this section of XML that I would like to use within the PropertyGrid. I'm looking for a way to use the property grid with my class to read and write this section as needed.

VB.NET:
<Material_Templates>
  <material_template name="Misc Spare Components">
   <template_code>W3T18</template_code>
  </material_template>
  <material_template name="1090 Template">
   <template_code>W3T6</template_code>
  </material_template>
  <material_template name="Purchase Sub Contract">
   <template_code>W3T9</template_code>
  </material_template>
 </Material_Templates>
 
Here's my class and the xml. Thanks.
VB.NET:
Private _ArrTempList As New ArrayList
Public Property ArrTempList As ArrayList
Get
ArrTempList = _ArrTempList
End Get
Set(value As ArrayList)
_ArrTempList = value
End Set
End Property
This is the section within my class reading this section of the xml.

This is the whole class. As you can see, I can use some help.
VB.NET:
Public Class BomManagerSettings
    Private _GblSource As String
    Public Property GblSource As String
        Get
            GblSource = _GblSource
        End Get
        Set(value As String)
            _GblSource = value
        End Set
    End Property
    Private _GblUpload As String
    Public Property GblUpload As String
        Get
            GblUpload = _GblUpload
        End Get
        Set(value As String)
            _GblUpload = value
        End Set
    End Property
    Private _GblTemp As String
    Public Property GblTemp As String
        Get
            GblTemp = _GblTemp
        End Get
        Set(value As String)
            _GblTemp = Environ("temp") & "\"
        End Set
    End Property
    Private _GblSite As String
    Public Property GblSite As String
        Get
            GblSite = _GblSite
        End Get
        Set(value As String)
            _GblSite = value
        End Set
    End Property
    Private _GblFlex3 As String
    Public Property GblFlex3 As String
        Get
            GblFlex3 = _GblFlex3
        End Get
        Set(value As String)
            _GblFlex3 = value
        End Set
    End Property
    Private _GblFlex5 As String
    Public Property GblFlex5 As String
        Get
            GblFlex5 = _GblFlex5
        End Get
        Set(value As String)
            _GblFlex5 = value
        End Set
    End Property
    Private _GblAllowNew As Boolean
    Public Property GblAllowNew As Boolean
        Get
            GblAllowNew = _GblAllowNew
        End Get
        Set(value As Boolean)
            _GblAllowNew = value
        End Set
    End Property
    Private _GblAllowMulitDrop As Boolean
    Public Property GblAllowMultiDrop As Boolean
        Get
            GblAllowMultiDrop = _GblAllowMulitDrop
        End Get
        Set(value As Boolean)
            _GblAllowMulitDrop = value
        End Set
    End Property
    Private _GblLocalSavePath As String
    Public Property GblLocalSavePath As String
        Get
            GblLocalSavePath = _GblLocalSavePath
        End Get
        Set(value As String)
            _GblLocalSavePath = value
        End Set
    End Property
    Private _GblAllowLocalSave As Boolean
    Public Property GblAllowLocalSave As Boolean
        Get
            GblAllowLocalSave = _GblAllowLocalSave
        End Get
        Set(value As Boolean)
            _GblAllowLocalSave = value
        End Set
    End Property
    Private _ArrTempList As New ArrayList
    Public Property ArrTempList As ArrayList
        Get
            ArrTempList = _ArrTempList
        End Get
        Set(value As ArrayList)
            _ArrTempList = value
        End Set
    End Property
    Private _ArrDropList As New ArrayList
    Public Property ArrDropList As ArrayList
        Get
            ArrDropList = _ArrDropList
        End Get
        Set(value As ArrayList)
            _ArrDropList = value
        End Set
    End Property
    Private _ArrBomSelection As New ArrayList
    Public Property ArrBomSelection As ArrayList
        Get
            ArrBomSelection = _ArrBomSelection
        End Get
        Set(value As ArrayList)
            _ArrBomSelection = value
        End Set
    End Property
    Private _TestPartExists As Boolean
    Public Property TestPartExists As Boolean
        Get
            TestPartExists = _TestPartExists
        End Get
        Set(value As Boolean)
            _TestPartExists = value
        End Set
    End Property
    Private _DefaultLanguage As String
    Public Property DefaultLanguage As String
        Get
            DefaultLanguage = _DefaultLanguage
        End Get
        Set(value As String)
            _DefaultLanguage = value
        End Set
    End Property
    Private _SapLanguage As String
    Public Property SapLanguage() As String
        Get
            SapLanguage = _SapLanguage
        End Get
        Set(value As String)
            _SapLanguage = value
        End Set
    End Property
    Public Sub New()
        Dim xmlFileName As String = My.Settings.XmlFileName
        Dim XmlFileSource As String = My.Settings.XmlFileSource
        Dim AppConfigFile As String = XmlFileSource & "\" & xmlFileName
        Dim doc As Xml.XmlDocument = New Xml.XmlDocument()
        doc.Load(AppConfigFile)
        Dim xmle As Xml.XmlElement = doc.DocumentElement
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/sourcepath")
            GblSource = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/uploadpath")
            GblUpload = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/testpartexists")
            TestPartExists = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/local_site_code")
            GblSite = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/flexfield_3")
            GblFlex3 = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/flexfield_5")
            GblFlex5 = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Upload_Site_Codes/upload_site")
            ArrDropList.Add(nod.InnerText)
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/Bom_Type/BoM_Selection")
            ArrBomSelection.Add(nod.InnerText)
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/allowlocalsave")
            GblAllowLocalSave = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/Allow_New")
            GblAllowNew = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/Allow_Multi_Drop")
            GblAllowMultiDrop = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Material_Templates/material_template")
            ArrTempList.Add(nod.Attributes("name").InnerText)
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/DefaultLanguage")
            DefaultLanguage = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/SAPLanguage")
            SapLanguage = nod.InnerText
        Next
        For Each nod As Xml.XmlNode In xmle.SelectNodes("//BOMi/Application_Configuration/localsavepath")
            GblLocalSavePath = nod.InnerText
        Next
        doc = Nothing
    End Sub

Here is the xml
VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<BOMi>
 <Application_Configuration>
  <Allow_New>True</Allow_New>
  <Allow_Multi_Drop>False</Allow_Multi_Drop>
  <DefaultLanguage>en-US</DefaultLanguage>
  <SAPLanguage>E</SAPLanguage>
  <sourcepath>c:\dwg\</sourcepath>
  <uploadpath>U:\Approve\</uploadpath>
  <localsavepath>c:\dwg\</localsavepath>
  <allowlocalsave>True</allowlocalsave>
  <testpartexists>True</testpartexists>
  <local_site_code>1050</local_site_code>
  <flexfield_3>Q10</flexfield_3>
  <flexfield_5/>
  <Bom_Type>
   <BoM_Selection>1</BoM_Selection>
   <BoM_Selection>3</BoM_Selection>
  </Bom_Type>
 </Application_Configuration>
 <Upload_Site_Codes>
  <upload_site>1050</upload_site>
 </Upload_Site_Codes>
 <Material_Templates>
  <material_template name="Misc Spare Components">
   <template_code>W3T118658</template_code>
  </material_template>
  <material_template name="1090 Template">
   <template_code>W3T68564</template_code>
  </material_template>
  <material_template name="Purchase Sub Contract">
   <template_code>W3T196829</template_code>
  </material_template>
 </Material_Templates>
</BOMi>
 
Back
Top