Vivek Thangaswamy
asked on
set DisplayMeber and ValueMember from XML using C#
Hi
I want to the displaymember and valuemember from XMLdocument to Combobox in Windows application
I am tring with the following code...
I want to the displaymember and valuemember from XMLdocument to Combobox in Windows application
I am tring with the following code...
System.Collections.Generic.List<KeyValuePair<string, string>> ComBoData = new List<KeyValuePair<string, string>>();
ComBoData.Add(new KeyValuePair<string, string>(xElm.GetAttribute("Title").ToString(), xElm.GetAttribute("ID").ToString()));
ddl_List.DataSource = ComBoData;
ddl_List.DisplayMember = ?
ddl_List.ValueMember = ?
ASKER
Hope this is correct
ddl_List.DisplayMember = "Key";
ddl_List.ValueMember = "Value";
But the result is nothing :(
even in ddl_List.text it has the value
ddl_List.DisplayMember = "Key";
ddl_List.ValueMember = "Value";
But the result is nothing :(
even in ddl_List.text it has the value
small letter (k) and (v)
ddl_List.DisplayMember = "key";
ddl_List.ValueMember = "value";
ddl_List.DisplayMember = "key";
ddl_List.ValueMember = "value";
ASKER
i tried small also ... same result :(
or pls provide full code
it's working for me, can you post full code...
ASKER
Chk this
foreach (System.Xml.XmlElement xElm in xDoc.DocumentElement.ChildNodes)
{
if (xElm.Name.ToLower() == "list")
{
try
{
System.Collections.Generic.List<KeyValuePair<string, string>> ComBoData = new List<KeyValuePair<string, string>>();
ComBoData.Add(new KeyValuePair<string, string>(xElm.GetAttribute("Title").ToString(), xElm.GetAttribute("ID").ToString()));
ddl_List.DataSource = ComBoData;
ddl_List.DisplayMember = "key";
ddl_List.ValueMember = "value";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
like...
Open in new window