Results 1 to 11 of 11

Thread: How to manually populate a DataComboBox [VB6]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question How to manually populate a DataComboBox [VB6]

    Given a Data Combo Box [Dcb] I need to find a way to populate it manually with 3 fields (Type, Category, Location).

    If this was an ordinary Combo Box I would do something like “ComboBox.Additem “Type”, 0” however that option does not seems available with Data Combo Boxes.


    You may ask why am I using a Data Combo Box, it seems to be the only combo box that the Dcb_Change() event is loaded by selecting one of the items from the dropdown. The regular Combo box does not, it waits for the user to actually Type something in the field (which should be disabled because he should only have to choose from the list)

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    in a regular combobox, set the style to 3 and the user wont be able to type their own stuff in the box, only be able to select from the dropdown list. And the click event is the event that fires when they select an item, either by using the mouse or by using they keyboard to change the selection

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    I tried that already (and just tried it again to be 100% sure).
    The Combox (Style = 2: Dropdown List) is perfect except that when I change the selected value the _Change() event is not fired.

    Should I be using a different event?

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    He already mentioned it... Click event

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by kleinma
    And the click event is the event that fires when they select an item, either by using the mouse or by using they keyboard to change the selection
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    yup they said it

    sorry i said set the style to 3 when you are right it is 2, i was thinking 3rd style, which of course is 2 in the 0 based index

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Completly my mistake, read way too fast and didn't even notice.
    Sorry for the misunderstanding on my part.
    Thank you all for the help


    Now this brings up another issue, using Style 2 doesn't allow me to start with the Combo Box empty (CB.TEXT = "").
    VB6 will not allow me to erase the generic CombBox1 name in the TEXT property (just wont let me, I can however in Style 0) and if I try via code (CB.TEXT = "") I get an error saying that it is READ ONLY.

    Any clues how to fix this?
    I just want it to start blank... Or at least let me choose what it says.
    Last edited by Shaitan00; Jul 8th, 2004 at 01:34 PM.

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    when using style 2:

    Combo1.ListIndex = -1

    will clear the combobox

    Combo1.Text = "HELLO"
    will work for setting the text ONLY IF the item "HELLO" actually is in the list

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Works like a charm but, as usual when coding, causes another problem.

    It seems that if, for example, we have selected something other then listindex = -1 (user chose 1st item), and proceed to hit the CLEAR key (should clear all fields) I will try to reset CB.Listindex = -1 to make it blank again however this launches the CLICK EVENT for that Combo Box thus causing a lot of issues and finally crashing the application.

    Is there another way to blank out the ComboBox or disable the Click Event when doing a Clear?

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    why not just check in the clickevent to make sure the listindex is >= 0 ????

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Now that was a damn good idea.
    Thanks, everything is working perfectly.
    I owe you one

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