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

Expert Comment

by:Sudhakar Pulivarthi
Comment Utility
0
 
LVL 19

Expert Comment

by:Daniel Van Der Werken
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Accepted Solution

by:
peter3244 earned 0 total points
Comment Utility
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
Comment Utility
Sorry  I meant to say that all the coomet relate to nodes not attributes.
0
 

Author Closing Comment

by:peter3244
Comment Utility
because

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now