?
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
Medium Priority
?
955 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
  • 3
  • 2
6 Comments
 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

839 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