المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : determine listbox items origin



C# Programming
12-02-2012, 04:06 AM
Hi,

I'm working on an application of which requires me to have one list-box to hold data.

I'm having a little issue when deleting an object from a list-box. The issue comes into play when I fill the list-box with items from TWO separate lists.

Normally to delete the object I would get it's index and then remove it from the list in a separate class then reload the list-box to reflect the changes but in certain instances I need to fill the list-box with objects from two different lists and determining the origin of the object to delete from one of the two lists, well I'm not entirely sure how to do this.

this code is populating the list-box control.
//clear all items in the listbox ViewListBox.Items.Clear(); //create the lists List listOfPickups = visits.listPickups(); List listOfdeliveries = visits.listDeliveries(); //populate ViewListBox.Items.AddRange(listOfPickups.ToArray()); ViewListBox.Items.AddRange(listOfdeliveries.ToArray());
this is how i delete when i am only loading the listbox from one list.
if (ViewListBox.SelectedIndex < 0) { EditSelectBtn.Enabled = false; DeleteSelectBtn.Enabled = false; } else { if (MessageBox.Show("are you sure you want to delete the selected item?", "Are You Sure?", MessageBoxButtons.YesNo) == DialogResult.Yes) { visits.removePickup(this.ViewListBox.SelectedIndex); //******* listbox. updateList("pickups"); } else { //clicked no so do nothing! ViewListBox.ClearSelected(); } }
Any help would be greatly appretiated.