Willie Trombone
Honorary Master
- Joined
- Jul 18, 2008
- Messages
- 60,038
I'm learning LINQ to XML and am trying some examples to get the hang of it.
I have an XML file that needs to be read and used to populate some Windows form fields including a Listbox. I wondered what the easiest way to approach this would be, I'd prefer not to use loops if possible.
The XML file looks like this:
The <Job> and <Field> elements are a dynamic list and are numbers are not predictable. There will always only be 2 <TableX> elements per <Job>.
On the windows form there is a combo box cbmJob that they user selects a job name from (populated at form open from the <Job> elements).
On update of the combo box, textbox fields for SrvName, AuthType, Login and Pass are populated according to the selected job's properties.
Text box fields for <Table1> and <Table2> as well as text boxes for IDFieldName properties for both are populated according to the selected job,
lastly, two seperate Listbox components are populated with the dynamic <Field> lists for the job's <Table1> and <Table2> elements.
How would I efficiently populate the text fields and Listboxes from the appropriate selected Job in the combo box? If possible, help with constructors and main code would be greatly appreciated! I've done plenty of googling and come up with various code snippets but never been able to implement them properly.
I have an XML file that needs to be read and used to populate some Windows form fields including a Listbox. I wondered what the easiest way to approach this would be, I'd prefer not to use loops if possible.
The XML file looks like this:
Code:
<Jobs>
<Job Name="Job1" SrvName="MyServer" AuthType="SQL" Login="user" Pass="pass">
<DB1 name="DB1_Name" />
<DB2 name="DB2_Name" />
<Table1 IDField="IDFieldName">
<Field name="F1_Name"/>
<Field name="F2_Name"/>
<Field name="F3_Name"/>
</Table1>
<Table2 IDField="IDFieldName">
<Field name="F1_Name"/>
<Field name="F2_Name"/>
<Field name="F3_Name"/>
</Table2>
</Job>
<Job Name="Job2" SrvName="MyServer2" AuthType="SQL" Login="user2" Pass="pass2">
<DB1 name="DB1_Name" />
<DB2 name="DB2_Name" />
<Table1 IDField="IDFieldName">
<Field name="F1_Name"/>
<Field name="F2_Name"/>
<Field name="F3_Name"/>
<Field name="F4_Name"/>
<Field name="F5_Name"/>
</Table1>
<Table2 IDField="IDFieldName">
<Field name="F1_Name"/>
<Field name="F2_Name"/>
<Field name="F3_Name"/>
<Field name="F4_Name"/>
<Field name="F5_Name"/>
</Table2>
</Job>
</Jobs>
The <Job> and <Field> elements are a dynamic list and are numbers are not predictable. There will always only be 2 <TableX> elements per <Job>.
On the windows form there is a combo box cbmJob that they user selects a job name from (populated at form open from the <Job> elements).
On update of the combo box, textbox fields for SrvName, AuthType, Login and Pass are populated according to the selected job's properties.
Text box fields for <Table1> and <Table2> as well as text boxes for IDFieldName properties for both are populated according to the selected job,
lastly, two seperate Listbox components are populated with the dynamic <Field> lists for the job's <Table1> and <Table2> elements.
How would I efficiently populate the text fields and Listboxes from the appropriate selected Job in the combo box? If possible, help with constructors and main code would be greatly appreciated! I've done plenty of googling and come up with various code snippets but never been able to implement them properly.
Last edited:
