Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Inserting a default item at the start of a combobox

Inserting a default item at the start of a combobox

Scheduled Pinned Locked Moved Visual Basic
performancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay Royall
    wrote on last edited by
    #1

    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

    I 1 Reply Last reply
    0
    • J Jay Royall

      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

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      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)

      J 1 Reply Last reply
      0
      • I Ian Shlasko

        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)

        J Offline
        J Offline
        Jay Royall
        wrote on last edited by
        #3

        OK, thanks a lot. Sounds like a good idea, will give it a go tomorrow. Thanks again for your help :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups