G
Guest
Hi to all,
I have a class (persons) that derives from collection base:
and another class (person) with this properties:
-ID
-Name
When i have complete filled the object Persons with all the persons, i put
each persons inside a ListBox following this:
this.ListBoxpersons.DataSource=AvailableApplications;
this.ListBoxpersons.ValueMember="ID";
this.ListBoxpersons.DisplayMember="Name";
this.ListBoxPersons.SelectedIndex=-1;
My problem comes when i want to delete a person from the listbox and from
the collection of course.
and to do that i make this:
//Take the object to remove from collection
objPersons.Delete(int.Parse(ListBoxPersons.SelectedIndex.ToString()));
//Then refresh the listbox
ListBoxPersons.DataSource=objPersons;
ListBoxPersons.ValueMember="ID";
ListBoxPersons.DisplayMember="Name";
ListBoxPersons.SelectedIndex=-1;
This works, except when i try to delete the last item of the ListBox. I dont
know why but i obtain an Exception of type
System.ArgumentOutRangeException, index was out of range. Must be
non-negative and less than the size of the colletion.
I would like to know if this way its the correct one to refresh a list box.
Thanks
Regards.
Josema
I have a class (persons) that derives from collection base:
and another class (person) with this properties:
-ID
-Name
When i have complete filled the object Persons with all the persons, i put
each persons inside a ListBox following this:
this.ListBoxpersons.DataSource=AvailableApplications;
this.ListBoxpersons.ValueMember="ID";
this.ListBoxpersons.DisplayMember="Name";
this.ListBoxPersons.SelectedIndex=-1;
My problem comes when i want to delete a person from the listbox and from
the collection of course.
and to do that i make this:
//Take the object to remove from collection
objPersons.Delete(int.Parse(ListBoxPersons.SelectedIndex.ToString()));
//Then refresh the listbox
ListBoxPersons.DataSource=objPersons;
ListBoxPersons.ValueMember="ID";
ListBoxPersons.DisplayMember="Name";
ListBoxPersons.SelectedIndex=-1;
This works, except when i try to delete the last item of the ListBox. I dont
know why but i obtain an Exception of type
System.ArgumentOutRangeException, index was out of range. Must be
non-negative and less than the size of the colletion.
I would like to know if this way its the correct one to refresh a list box.
Thanks
Regards.
Josema