Inserting a default item at the start of a combobox
-
Hi, Throughout my application I have several ComboBoxes which are data bound to a collection of objects (uaually a generic list). Because the user needs the option to not select an item in the Combobox I need an empty item at the start which says something like "Please Select". The way I am doing this currently is to add an extra object to the start of my collection which gives me what I want. However, because a lot of these Comboboxes are bound to a collection of objects that are built when the application starts and remains in memory for the duration of the users' session, it means that my collections have an extra object in them which is causing problems elsewhere in the application. Is there any other way of inserting an item into the start of a combobox that is bound to a collection of objects? I hope this makes sense, if not then please let me know and I will try to clarify. Thanks for your time. Jay
-
Hi, Throughout my application I have several ComboBoxes which are data bound to a collection of objects (uaually a generic list). Because the user needs the option to not select an item in the Combobox I need an empty item at the start which says something like "Please Select". The way I am doing this currently is to add an extra object to the start of my collection which gives me what I want. However, because a lot of these Comboboxes are bound to a collection of objects that are built when the application starts and remains in memory for the duration of the users' session, it means that my collections have an extra object in them which is causing problems elsewhere in the application. Is there any other way of inserting an item into the start of a combobox that is bound to a collection of objects? I hope this makes sense, if not then please let me know and I will try to clarify. Thanks for your time. Jay
How about creating a wrapper class over the list, that adds the null element? Just need a class that implements IList<whatever> and passes all operations through to the underlying list, except that it returns a count one higher than the list count, subtracts one from all provided indices, and returns null for element #0.
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels) -
How about creating a wrapper class over the list, that adds the null element? Just need a class that implements IList<whatever> and passes all operations through to the underlying list, except that it returns a count one higher than the list count, subtracts one from all provided indices, and returns null for element #0.
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)OK, thanks a lot. Sounds like a good idea, will give it a go tomorrow. Thanks again for your help :)