Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

I need to display list of records from XML file in combo box.using C#.any suggestions please.

What I have tried:

    //ProcessStartInfo Sinfo=new ProcessStartInfo("http://192.168.0.74/gethospitals_test.php?hid=3&sno=1");
    //Process.Start(Sinfo);
    loadcombo();
}
var xmlDocument = XDocument.Load(fileName);
Posted
Updated 22-Apr-18 20:36pm
Comments
Maciej Los 23-Apr-18 1:46am    
What exactly do you want to load into combobox?
What's your xml structure?
Member 13777104 23-Apr-18 4:10am    
below is my xml, need to get hospital names(hname) in combo box.
?xml version="1.0" encoding="utf-8" ?>
<hospitals>
<hids>
<hid>1
<hos_type>0
<hcode>SV
<hname>St Vincents
Australia</address >
<landline>56456456456
<mobile>569678768
<email>bijibtrack1@gmail.com
<status>0
<created_by>fgdfgdfgdfg
<created_on>2011-02-26 10:10:50
<notes>dfgdfgdfg
<is_pms>0
<c_insert>1
<c_update>0
<c_timezone>

<hids>
<hid>2
<hos_type>0
<hcode>ARC
<hname>ARC Clinic
Australia.</address >
<landline>34563456
<mobile>34563456
<email>bijibtrack1@gmail.com
<status>1
<created_by>
<created_on>2012-10-10 00:00:00
<notes>australia
<is_pms>0
<c_insert>1
<c_update>0
<c_timezone>2011-02-11 18:27:09
Patrice T 23-Apr-18 17:23pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Richard MacCutchan 23-Apr-18 4:27am    
You already ;posted this in the C# forum; please do not repost.

1 solution

LINQ to XML (C#) | Microsoft Docs[^] is probably what you're looking for.

C#
XDocument xdoc = XDocument.Load("xmlfullfilename.xml");
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("hname", typeof(string)));
dt = xdoc.Descendants("hname")
    .Select(x=>dt.LoadDataRow(new object[]{x.Value}, false))
    .CopyToDataTable();
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "hname";


For further details, please see:
LINQ to XML Overview[^]
Samples (LINQ to XML)[^]
How to: Bind a Windows Forms ComboBox or ListBox Control to Data | Microsoft Docs[^]

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900