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

  • SEARCH
  • Home
  • 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 a client was concerned that their SWF was insecure because the XML path
Recently, I meet some tasks about the char/string on windows platform. I see that
Recently, I started changing some of our applications to support MS SQL Server as
Recently I had to type up some documentation on .net data providers and ado.net.
Recently i've switched to PHP 5.3+ and after that migration i learned that the
Recently I've started to develop Android Soft Keyboard and got some problem with preferences.
Recently, I've been running some tests with C++ and VB.NET to compare execution speeds.
Recently we added a audit_logs table to the database, and after some frustration I
Recently I just finished a simple Facebook Air application, and some of my friends
Recently I've discovered CouchDB. I want to use CouchApp to build a flash games

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.