Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:07:20+00:00 2026-05-23T00:07:20+00:00

Hi I am trying to read XML File using XLinq and binding the values

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:07:21+00:00Added an answer on May 23, 2026 at 12:07 am

    Your current query produces an IEnumerable<XElement> , that doesn’t give you the properties you want.

       // not tested
       var res = from c in xmlDoc.Element("Clients").Descendants("Client")
       select new { Name=c.Element("Name").Value, ID = c.Element("ID").Value };
    
       ...
       cmb1.DataSource = res.ToList();
    

    The ID will be a string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read an XML file into a data set using dataset.ReadXml(fileName,
I'm trying to read a dataset as xml and load it into an XML
I am currently trying to load a slightly large xml file into a dataset.
I am trying to read an XML file using LINQ. I have had no
Trying to read into an object the following XML file (can be changed) into
I'm trying to read a Log4net XMLLayout output log file using Log4View. <?xml version=1.0?>
I'm currently trying to read the contents of an XML file into a Map
I've been trying to read an XML-file using VB.NET and after some (see 2-3
I'm trying to read an object from a XML file using XMLDecoder. The construction
I am trying to read from an ncx file (i.e. xml file) using XElement:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.