Solved

Help with loading combobox from xml file using VB.NET

Posted on 2016-08-13
18
71 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL and CLR parameter strings 9 63
Open telerik datetime picker programmatically 13 42
Adding Rows to Grid 4 32
Datatable / Dates ? 4 29
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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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