Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete selected "multiple items" from bound ListBox 1

Status
Not open for further replies.

DanielXIX

Programmer
Jul 31, 2005
18
TR
Hi All!
my code is...

Code:
private void btnDelete_Click(object sender, System.EventArgs e)
		{
		
			XmlTextReader myXmlReader = new XmlTextReader("c:\\AdressBook.xml");
			DataSet myDataSet = new DataSet();
			myDataSet.ReadXml(myXmlReader);
			myXmlReader.Close();

             lstAdressBook.DataSource=myDataSet.Tables[0];
			lstAdressBook.DisplayMember="name";
			lstAdressBook.ValueMember="email";
			try
DataTable MyDataTable = (DataTable)lstAdressBook.DataSource;
ArrayList myarray = new ArrayList(lstAdressBook.SelectedIndices);
			for(int i = myarray.Count; i>0; i--)				{
					int myindex = i-1;
					MyDataTable.Rows.RemoveAt((int)myarray[myindex]);
				}
myDataSet.WriteXml("c:\\AdressBook.xml");
	


			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
	
	}


i have had an error with my code .it always deletes first item of listbox items in listbox,but i want to delete all selected items .

what is the problem ? How can i delete all selected items in listbox?

Regards.
Daniel.
 
Why are you populating the list box from an xml file before deleting the selected items?

I'm assuming you already have the list box populated. If you re-populate it when the delete button is clicked, you probably lose all selections, therefore nothing gets deleted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top