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 947685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:07:10+00:00 2026-05-15T23:07:10+00:00

I recently databounded an xml file to a listbox. Now I want to write

  • 0

I recently databounded an xml file to a listbox. Now I want to write some function to add or delete items from that listbox. The following error came up while trying listbox.items.add or listbox.items.insert:

Access and modify elements with ItemsControl.ItemsSource instead.

I googled this and it said to work on the ‘model’ instead,

However I have no clue how to do that. So how can I add or delete items to and from the datasource? I would hate having to add xml elements and values to the original and then update the file as the data source…

  • 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-15T23:07:11+00:00Added an answer on May 15, 2026 at 11:07 pm

    How about loading the XML into a dataset and then manipulating the dataset and rebinding?

    Instead of using the XML file and binding that to the listbox, try this: (source)

     string myXMLfile = "C:\\MySchema.xml";
        DataSet ds = new DataSet(); 
        try
        {
            //reads file and loads data into dataset
            ds.ReadXml(myXMLfile);
            //set the listbox's datasource to the dataset
            //note that if you have complex XML then you might need to set this to one of the datatables in the datset to get what you want
            listBox1.DataSource = ds;
            listBox1.DataBind();
        }
        catch (Exception ex)
        {
          //Handle error
        }
    

    Lets assume you XML is rather simple. To add a tow to the DataSet you would do: (source)

    //if customers is the name of your table (have not seen your XML)
    DataRow newCustomersRow = ds.Tables["Customers"].NewRow();
    
    newCustomersRow["CustomerID"] = "ALFKI";
    newCustomersRow["CompanyName"] = "Alfreds Futterkiste";
    
    dataSet1.Tables["Customers"].Rows.Add(newCustomersRow);
    

    Here is an XML example that should work with the above:

    <Data>
      <Customers>
        <Customer>
          <CustomerID>123</CustomerID>
          <CompanyName>Name</CompanyName>
        </Customer>
      </Customers>
    </Data>
    

    I have not compiled or tried to run any of that, but you should get the general idea and adapt it to your code.

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

Sidebar

Related Questions

Recently I'm doing some work on RTMP streaming, that is using Flowplayer to integrate
Recently I've studied the backpropagation network and have done some manual exercise. After that,
Recently there was some upgrade happened from frame work 2.0 to 4.0, so after
Recently my records started to disappear from my application's database so I want to
Recently, I had the need for a function that I could use to guarantee
Recently I've found how to add a link to an item in Visual Studio
Recently, I was writing a class in which I discovered that I could reduce
Recently the PHP manual started showing the following warning on every mysql function page:
Recently I have released my app into the US AppStore. Now I Planed for
Recently, I was asked to compile some of my Android projects, based on the

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.