Solved

c# setting up combo box using xml as datasource. How do I make DisplayMember and valueMember attributes of a xml node

Posted on 2011-02-28
6
949 Views
Last Modified: 2012-05-11
c# setting up combo box using xml as datasource. How do I make DisplayMember and valueMember attributes of a xml node
0
Comment
Question by:peter3244
[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
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34998096
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 34998122
Well, we don't have your XML source, but here's a go at this:

You'd grab the document and load it as an XmlDocument:

XmlDocument xDoc = new XmlDocument();
xDox.Load( xmlSource -- whatever that is );

Then, you'd grab all the nodes of interest:

XmlNodeCollection xmlNodes = xDoc.GetNodes( xpathToNodes );

Then, loop through the nodes, getting the values you want:

foreach( XmlNode node in xmlNodes )
{
   string value1 = node.SelectSingleNode( xpath );
   combobox.Items.Add( value1 );
}

...more or less.
0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34998136
Hi,

Your xml should be:
<Job>
  <CurrentJob>45342</CurrentJob>
 <Driver>
  <DriverName>JSmith</DriverName>
  <EmployeeId>1</EmployeeId>
  </Driver>
 <Driver>
  <DriverName>BWhite</DriverName>
  <EmployeeId>2</EmployeeId>
  </Driver>
 <Driver>
  <DriverName>IBrown</DriverName>
  <EmployeeId>3</EmployeeId>
  </Driver>
  </Job>

Display Member is DriverName
Value Member is EmployeeId

Use like this in ur scenario too.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
peter3244 earned 0 total points
ID: 34998802
No because you are talking about nodes not atrributes.  However if you I have discovered through trail and error
that it can be done using a dataset


            cmbField.DataSource = ds.Tables["field"];
            cmbField.DisplayMember = "name";

where field is a node and name is an attribute.
0
 

Author Comment

by:peter3244
ID: 34998832
Sorry  I meant to say that all the coomet relate to nodes not attributes.
0
 

Author Closing Comment

by:peter3244
ID: 35042604
because

1) The first was a cut and paste of a link
2) the other was incorrect
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

696 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