Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
954 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

618 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