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. How to make an item to be selected by default in combobox

How to make an item to be selected by default in combobox

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestion
4 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.
  • P Offline
    P Offline
    Pradip Kishore
    wrote on last edited by
    #1

    Hi, I am retrieving some values from database & populating them in a combobox.Prior to populating the values from the combobox,i manually added an item as "All" and i want that this item should be the default selected item(with index -1) when the values will be populated from the database into the combobox. Can anybody help me how to do this..? Thanks in advance

    i m Pradip Kishore

    C 1 Reply Last reply
    0
    • P Pradip Kishore

      Hi, I am retrieving some values from database & populating them in a combobox.Prior to populating the values from the combobox,i manually added an item as "All" and i want that this item should be the default selected item(with index -1) when the values will be populated from the database into the combobox. Can anybody help me how to do this..? Thanks in advance

      i m Pradip Kishore

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Pradip Kishore wrote:

      I am retrieving some values from database & populating them in a combobox.Prior to populating the values from the combobox,i manually added an item as "All" and i want that this item should be the default selected item(with index -1)

      You can do that, provided you don't insist on the with index -1 requirement (-1 is used to mark the no selection state). If you add te "All" item manually (and the combo has NOT the sort style set) then it will have index 0, hence you just select item 0 to perform the task. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      P 1 Reply Last reply
      0
      • C CPallini

        Pradip Kishore wrote:

        I am retrieving some values from database & populating them in a combobox.Prior to populating the values from the combobox,i manually added an item as "All" and i want that this item should be the default selected item(with index -1)

        You can do that, provided you don't insist on the with index -1 requirement (-1 is used to mark the no selection state). If you add te "All" item manually (and the combo has NOT the sort style set) then it will have index 0, hence you just select item 0 to perform the task. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        P Offline
        P Offline
        Pradip Kishore
        wrote on last edited by
        #3

        Hi Thanks for your answr. But my requirement is that when the page will be loaded then the default selected item in the combobox should be "all" i added "all" as combobox.iteams.add("all") now i want to make "all" as my default selected item of the combobox. Please revert back soon.

        i m pradip kishore from india,working in vb.net & asp.net

        C 1 Reply Last reply
        0
        • P Pradip Kishore

          Hi Thanks for your answr. But my requirement is that when the page will be loaded then the default selected item in the combobox should be "all" i added "all" as combobox.iteams.add("all") now i want to make "all" as my default selected item of the combobox. Please revert back soon.

          i m pradip kishore from india,working in vb.net & asp.net

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          combobox.SelectedIndex = 0 should do the job for you. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          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