Solved

Help with loading combobox from xml file using VB.NET

Posted on 2016-08-13
18
60 Views
Last Modified: 2016-08-14
Hi,

How do you modify the code below to load a combobox with columns from an xml file using VB.NET? Also when placing the cursor on a particular row, how do you display its description? Need to describe desceiption for each row I place the cursor on.        

 Dim xmlPath1 As String
        Dim dtsetcol1 As New DataSet
        'Load Grrid
        xmlPath1 = System.IO.Path.Combine(Application.StartupPath + "\MainTest.xml")  'grid1
        dtsetcol1.Clear()
        dtsetcol1.ReadXml(xmlPath1)
        'MsgBox(dtsetcol1.Tables(0))
        Me.ComboBox3.DataSource = dtsetcol1.Tables(0).Columns(0).ColumnName

Thanks,

Victor
0
Comment
Question by:vcharles
  • 9
  • 7
  • 2
18 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41754839
Hi Victor;

Victor, Victor, Victor if you want a solution using XML you need to provide the schema of the XML.
Which nodes from the XML you wish to display in the ComboBox and which nodes you will be using for the description?

Thanks
0
 

Author Comment

by:vcharles
ID: 41754950
Hi Fernando,

Below is an example of the XML file. Also, when the mouse is placed on SN, would like to display Serial Number next to SN.

<Root>
  <Fields>
    <SCOUNTRY />
    <SN />
    <COUNTRY />
    <AGD4 />
    <FIF />
    <NSN />
    <RN />
    <NAS />
</Fields>
</Root>

Thanks,

Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41754960
Victor,

From my last post, "Which nodes from the XML you wish to display in the ComboBox", I am assuming that is the XML node with the tag name SN?

Will the value in the SN node will it come from the Inner XML? Or is it an Attribute of SN? If Attribute what is its name?

Also where do you want to display the Description seeming there is no event as the cursor changes through the ComboBox list of items? One solution would be to display it in th TextBox above the dropdown list? So you select a SN but it display a Description or do you want something else, please advise.

From my last post, "which nodes you will be using for the description?", I have no idea.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:vcharles
ID: 41755018
Hi Fernando,

I would like ro display all the nodes /data elements in the dropdown list,  not the values, as you suggested, when the user places the cursor on a particular row I would like to display its description in a textbox. The file I sent is just an example, will modify your slution to work with the actual xml file.

Thanks,
Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41755025
Victor may not be talking about the same thing. A ComboBox only displays one column from a DataSource, so how are you going to do this, "I would like ro display all the nodes /data elements in the dropdown list"??
0
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 41755043
Is this a WinForms project?
0
 

Author Comment

by:vcharles
ID: 41755066
Ok, in that case it would not work, will need to create another xml file where the column names are included in one column.

Thanks,

Victor
0
 

Author Comment

by:vcharles
ID: 41755067
Yes it is a Windoes project.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41755082
To your statement, "Ok, in that case it would not work, will need to create another xml file where the column names are included in one column.", Why.

It would help if you give a accurate XML file and then show what info from the XML you want in the dropdown list.
0
 

Author Comment

by:vcharles
ID: 41755177
Hi Fernando,

I need to create a new xml file to include the column names in the Fields column.

 <Root>
<Fields>
<FieldsN>SN</FieldsN>
</Fields>
<Fields>
 <FieldsN>COUNTRY</FieldsN>
</Fields>
<Fields>
   <FieldsN>AGD4</FieldsN>  
</Fields>
<Fields>
 <FieldsN>FIF</FieldsN>
</Fields>
<Fields>
<FieldsN>NSN</FieldsN>  
</Fields>
<Fields>
 <FieldsN>RN</FieldsN>  
</Fields>
<Fields>
<FieldsN>NAS</FieldsN>
</Fields>
 </Root>

Thanks,

Victor
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41755460
Here you go Victor.
Dim xmlPath1 As String
xmlPath1 = System.IO.Path.Combine(Application.StartupPath + "\MainTest.xml")
Dim xdoc = XDocument.Load(xmlPath1)

Dim cboData = (From d In xdoc.Root.Descendants("FieldsN")                   
               Select d.Value).ToList()

ComboBox1.DataSource = cboData

Open in new window

0
 

Author Comment

by:vcharles
ID: 41755492
Hi Fernando,

Thank you.

If I place the cursor on SN how do I display Serial Number in a textbox?

Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41755500
What Serial Number?
0
 

Author Comment

by:vcharles
ID: 41755507
The description of SN, I would like to see the description when I place the cursor on the items listed in the dropdownbox.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41755562
I asked this question, "From my last post, "which nodes you will be using for the description?", I have no idea.", in a previous post [here] but it has gone unanswered.
0
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 41755569
Why don't you post a sample XML file?

Do you know about ToolTip?
0
 

Author Comment

by:vcharles
ID: 41755630
Hi Fernando,

I would like to know how it works with one node (i.e.  SN), can modify the code to work with all the Nodes I need a description..

Thanks

Victor
0
 

Author Closing Comment

by:vcharles
ID: 41755744
Thank You
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question