?
Solved

Help with loading combobox from xml file using VB.NET

Posted on 2016-08-13
18
Medium Priority
?
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 2
18 Comments
 
LVL 63

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 63

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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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 63

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 63

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 63

Accepted Solution

by:
Fernando Soto earned 2000 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 63

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 63

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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 …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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