Hi I am trying to read XML File using XLinq and binding the values into Combo Box:-
XDocument xmlDoc = XDocument.Load("abc.xml");
var res = from c in xmlDoc.Element("Clients").Descendants("Client")
select c;
cmb1.BindingContext = new BindingContext();
cmb1.DataSource = res;
cmb1.DisplayMember = "Name";
cmb1.ValueMember = "ID";
My XMl structure is something like this:-
<Clients>
<Client>
<ID>-1</ID>
<Name>--Select--</Name>
</Client>
<Client>
<ID>1</ID>
<Name>A</Name>
</Client>
<Client>
<ID>2</ID>
<Name>B</Name>
</Client>
<Client>
<ID>3</ID>
<Name>C</Name>
</Client>
<Client>
<ID>4</ID>
<Name>D</Name>
</Client>
</Clients>
But somehow i am getting errors. Pleas help
Error is:-
System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource.
at System.Windows.Forms.ListControl.set_DataSource(Object value)
Your current query produces an
IEnumerable<XElement>, that doesn’t give you the properties you want.The ID will be a string.