Solved

Help with loading combobox from xml file using VB.NET

Posted on 2016-08-13
18
49 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
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
Comment Utility
Is this a WinForms project?
0
 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
Yes it is a Windoes project.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
What Serial Number?
0
 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
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
Comment Utility
Why don't you post a sample XML file?

Do you know about ToolTip?
0
 

Author Comment

by:vcharles
Comment Utility
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
Comment Utility
Thank You
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now