Combo Box Question - Is there a better way? 
Author Message
 Combo Box Question - Is there a better way?

Hi Enzo:

Quote:
>I have worked in other environments where the the Combo box control could
be
>given two values.  The first value was the return value and the second
value
>was the display value.  The is very useful for database work

The DBCombo control can do this, if you store your data in a database.

Doug.



Sun, 22 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?
I have worked in other environments where the the Combo box control could be
given two values.  The first value was the return value and the second value
was the display value.  The is very useful for database work.  For example,
you might want the user to see the department name say "Accounting" but you
want your Combo box to return say the department number "1001".  Right now,
I have been handling this with an array that stores a user defined type.
For example:

Type  picklist_type
        return_val    as    string
        display_val    as    string
end type

Dim dept_array() as picklist_type

This is a pain because everytime the user selects a value from the combo
box, I need to then search the array for the value.  Not to mention I have
to use twice the resources because the data is stored in the Combo Box list
and in the array.

Is there another way to do this?

Thanks,

Enzo Maini



Mon, 23 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?
Check out th ItemData, NewIndex and ListIndex properties of the ComboBox
control. It is an implicit 'array' of Longs. Some sample code:

    Combo1.AddItem "Some Data1"
    Combo1.ItemData(Combo1.NewIndex) = <some number1>
    Combo1.AddItem "Some Data2"
    Combo1.ItemData(Combo1.NewIndex) = <some number2>

In the click/change event

    if Combo1.ListIndex = -1 then Exit Sub
    Msgbox "Your 'key': " & Combo1.ItemData(Combo1.ListIndex)

Note (I once got burned by this) - if your Combo1.Style = 2 then the Change
event is NOT triggered, as stated in te on-line help

... Jeff

Quote:

>Hi Enzo:

>>I have worked in other environments where the the Combo box control could
>be
>>given two values.  The first value was the return value and the second
>value
>>was the display value.  The is very useful for database work

>The DBCombo control can do this, if you store your data in a database.

>Doug.



Mon, 23 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?
have example on-line with data base and dbcombo

http://www.itcanada.com/~netters

Quote:
>I have worked in other environments where the the Combo box control could be
>given two values.  The first value was the return value and the second value
>was the display value.  The is very useful for database work.  For example,
>you might want the user to see the department name say "Accounting" but you
>want your Combo box to return say the department number "1001".  Right now,
>I have been handling this with an array that stores a user defined type.
>For example:

>Type  picklist_type
>        return_val    as    string
>        display_val    as    string
>end type

>Dim dept_array() as picklist_type

>This is a pain because everytime the user selects a value from the combo
>box, I need to then search the array for the value.  Not to mention I have
>to use twice the resources because the data is stored in the Combo Box list
>and in the array.

>Is there another way to do this?

>Thanks,

>Enzo Maini



http://www.itcanada.com/~netters


Mon, 23 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?
So, what do you do if you want your 'ItemData' to be non-numeric?

David Phillips



Quote:
> Check out th ItemData, NewIndex and ListIndex properties of the ComboBox
> control. It is an implicit 'array' of Longs. Some sample code:

>     Combo1.AddItem "Some Data1"
>     Combo1.ItemData(Combo1.NewIndex) = <some number1>
>     Combo1.AddItem "Some Data2"
>     Combo1.ItemData(Combo1.NewIndex) = <some number2>

> In the click/change event

>     if Combo1.ListIndex = -1 then Exit Sub
>     Msgbox "Your 'key': " & Combo1.ItemData(Combo1.ListIndex)

> Note (I once got burned by this) - if your Combo1.Style = 2 then the
Change
> event is NOT triggered, as stated in te on-line help

> ... Jeff


> >Hi Enzo:

> >>I have worked in other environments where the the Combo box control
could
> >be
> >>given two values.  The first value was the return value and the second
> >value
> >>was the display value.  The is very useful for database work

> >The DBCombo control can do this, if you store your data in a database.

> >Doug.



Tue, 24 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?

Quote:

> So, what do you do if you want your 'ItemData' to be non-numeric?

> David Phillips

Store your 'Item' in an appropreate array and store the array index
in the ItemData property.

LFS



Tue, 24 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?


Fri, 19 Jun 1992 00:00:00 GMT  
 Combo Box Question - Is there a better way?
Thanks all for the replies,

I am using Jeffery Klien's suggestion.  This works for my current situation
because it returns an index into my array which eliminates the search that I
perform now.

Enzo

Quote:

>I have worked in other environments where the the Combo box control could
be
>given two values.  The first value was the return value and the second
value
>was the display value.  The is very useful for database work.  For example,
>you might want the user to see the department name say "Accounting" but you
>want your Combo box to return say the department number "1001".  Right now,
>I have been handling this with an array that stores a user defined type.
>For example:

>Type  picklist_type
>        return_val    as    string
>        display_val    as    string
>end type

>Dim dept_array() as picklist_type

>This is a pain because everytime the user selects a value from the combo
>box, I need to then search the array for the value.  Not to mention I have
>to use twice the resources because the data is stored in the Combo Box list
>and in the array.

>Is there another way to do this?

>Thanks,

>Enzo Maini




Wed, 25 Apr 2001 03:00:00 GMT  
 Combo Box Question - Is there a better way?


Fri, 19 Jun 1992 00:00:00 GMT  
 Combo Box Question - Is there a better way?
See vbHelp for combo boxes/list boxes "index" property


Thu, 26 Apr 2001 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. combo box/database combo box vlaue question - newbie

2. Combo Box Question - Is there a better way?

3. Combo Box help, need a better combo

4. Timer Question - I have explained better what I am looking for

5. enter data in a combo box based on value from another combo box

6. Limit subform combo box by selection in parent combo box

7. Best way to requey a combo box

8. Want Access combo box to filter rowsource of another combo box

9. Populating a combo box from another combo box

10. Populate a combo box from another combo box selection

11. selecting records for 2nd combo box dependant on first combo box

12. Help filling second combo box from fist combo box

 

 
Powered by phpBB® Forum Software