?
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
?
951 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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