Solved

Help with loading combobox from xml file using VB.NET

Posted on 2016-08-13
18
55 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
 

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
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: 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Anyway to make "All" the default in the dropdown? 6 34
What .NET URL re-routing tool did I use? 2 34
ASP.NET 5 Templates 2 65
Javascript and Jquery not firing 9 37
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

929 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

8 Experts available now in Live!

Get 1:1 Help Now