CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2000
    Location
    NM
    Posts
    122

    Simple Combo Box Control Question...

    Hello, I have a combo box on my form which style has to be 2-Drop Down list. There is an instance though where i load data onto the form from a database, and I want to set the combo box whose style is 2 to a integer i grab from the database. It keeps saying since its style is two that its a read only. I cannot change the style since what I load from the DB is a control ID that the user cannot change, but I read and save out that Id from the combo box on the save/edit. Any way to set this combo box to the number I need by searching its array some how? Code would help. Thanks

    Regards,
    Shane



  2. #2
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: Simple Combo Box Control Question...

    Could you include some code?
    I tried this:

    option Explicit

    private Sub Command1_Click()
    me.Combo1.Text = "3"
    End Sub

    private Sub Form_Load()
    me.Combo1.AddItem "1"
    me.Combo1.AddItem "2"
    me.Combo1.AddItem "3"
    me.Combo1.AddItem "4"
    End Sub



    It worked fine for me.
    This was in a new project where combo1 is style 2. Is this what you were trying to do?

    thanx/good luck,
    adam
    thanx/good luck

  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Simple Combo Box Control Question...

    For a combo box with the Drop Down list style, you cannot set the text using the combo1.text = "Something". You do it using the ListIndex property. You should know the ListIndex of the item you want to display (or you can search using a for loop) then set Combo1.ListIndex to that value.




  4. #4
    Join Date
    Oct 2000
    Location
    NM
    Posts
    122

    Re: Simple Combo Box Control Question...

    Hmm okay I get the listindex, i wasn't sure how to search the combo box. What were those methods?

    Thanks

    -Shane



  5. #5
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Simple Combo Box Control Question...


    Just FYI. You can set Combo1.text = "Something" as long as "Something" is in the list. This means that the item must be added to the list first. To do
    combo1.additem "Something"
    combo1.text = "Something" is perfectly okay.

    David Paulson

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