Hi All!
my code is...
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.
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.