Results 1 to 11 of 11

Thread: [RESOLVED] Combobox default item

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Resolved [RESOLVED] Combobox default item

    How can I make a comboxbox list the first item in the collaction by default

    in other words i have a collection list

    1
    2
    3
    4
    5

    When program loads I want combobox to load 1

    Thanks

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Combobox default item

    did you tried:

    Code:
      ComboBox1.SelectedIndex = 0
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Combobox default item

    Tip: you can set the combobox DropDownStyle property to DropDownList

    this will remove the empty value from your combobox.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  4. #4
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Arrow Re: Combobox default item

    use following code
    Code:
    Combobox.selectedIndex = 1
    basically, Combobox.selectedIndex will accept/returns an integer value of item in List
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Combobox default item

    Quote Originally Posted by motil View Post
    Tip: you can set the combobox DropDownStyle property to DropDownList

    this will remove the empty value from your combobox.
    Thats what I thought but it doesnt work??

  6. #6
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Combobox default item

    do you set the selectedindex to 0 after you populating the cb?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  7. #7
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Arrow Re: Combobox default item

    hey billboy,

    u have 5 items in your cmbbox, isn't it ???
    so u have bydefault 1 as selected always..right ???

    if u want the same then just fill the list and then after populating it...set selectedIndex = 1
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Combobox default item

    I must be blind i dont see a property setting for selected index, do I have to code it ??

  9. #9
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Combobox default item

    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ComboBox1.Items.Add("1")
            ComboBox1.Items.Add("2")
            ComboBox1.Items.Add("3")
            ComboBox1.Items.Add("4")
            ComboBox1.SelectedIndex = 0
    
    
        End Sub
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  10. #10
    Hyperactive Member koolprasad2003's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    443

    Arrow Re: Combobox default item

    you have to do code for it like this...

    just do the code on your form load event
    Code:
    //fill combo box code here
    Combobox1.selectedIndex = 1
    MCP, MCTS, Microsoft MVP [Asp.Net/IIS]

    For more .NET development tips visit .NET Tips

    If the post is useful then please Rate it

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Combobox default item

    Quote Originally Posted by motil View Post
    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ComboBox1.Items.Add("1")
            ComboBox1.Items.Add("2")
            ComboBox1.Items.Add("3")
            ComboBox1.Items.Add("4")
            ComboBox1.SelectedIndex = 0
    
    
        End Sub
    ok thanks
    I thought there was aproperty setting in the propertys window i was missing
    LOL

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width