CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Posts
    218

    help with combobox

    dear,
    how to add the item
    Code:
    combobox1.AddItem "1"
    this code cannot do that.

  2. #2
    Join Date
    Jan 2006
    Location
    Bangalore, India
    Posts
    209

    Re: help with combobox

    Hi,

    Check whether the name of your combo box is combobox1.

    The default name is Combo1.

    To add with it, use

    Code:
    Combo1.AddItem "1"

  3. #3
    Join Date
    Feb 2004
    Posts
    218

    Re: help with combobox

    thank you. but i rename the combobox as combobox1, and want to add a new item to exsiting items. but use such code cannot archieve that, help me.

  4. #4
    Join Date
    Jan 2006
    Location
    Bangalore, India
    Posts
    209

    Re: help with combobox

    Hi,

    Post your project here.

  5. #5
    Join Date
    Apr 2006
    Posts
    11

    Re: help with combobox

    Hi
    Just tried it out, works fine.

    Code:
     
    Dim j as integer 
    Private Sub Form_Load()
    	Combobox1.Clear
    	For J = 1 To 10
    		Combobox1.AddItem J
    	Next J
    	Combobox1.Text = Combobox1.List(0)
    End Sub
    Cheers
    Karsten

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: help with combobox

    Quote Originally Posted by liuyang
    Hi
    Just tried it out, works fine.

    Code:
     
    Dim j as integer 
    Private Sub Form_Load()
    	Combobox1.Clear '1
    	For J = 1 To 10
    		Combobox1.AddItem J
    	Next J
    	Combobox1.Text = Combobox1.List(0) '2
    End Sub
    Cheers
    Karsten
    Hi Karsten!
    I noticed 2 things in your code:
    1) You do not need to clear the combobox at form load - Form Load is fired when your form gets loaded into memory, so you can see Form Load as the firts event that fires for your form (in this case)

    2) I also see that your For Loop starts at 1. Combobox's ListIndexes are 0 based, meaning that the first item in a combobox is 0, not 1 - so if you want to add 10 items to your combobox, you can start the loop at 0, and end it at 9.

    just my 2 cents..

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

Featured