Announcement

Collapse
No announcement yet.

VB ComboBox ItemData Equivalent?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB ComboBox ItemData Equivalent?

    Hi! I'm creating a recordset from my database with two fields
    in it. They are:

    iCompanyId Integer - Unique Identifier
    vchCompanyName varchar(100)

    I want to display the vchCompanyName field values in a combobox for the user to choose the company they want to do work on. Is there a way to store both the iCompanyId and vchCompanyName values in the combo box but only display the vchCompanyName data? This would be similar to the ItemData property for Visual Basic combo boxes. I want the user to choose the company by name but I want the program to use the Unique ID field to do the work. Any help would be much appreciated.

    Regards,
    Scott
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

  • #2
    I think I just found it:

    To set the itemdata:

    '------------------------------------------------------------------------------
    ' TITLE: Combo_SetItemData
    ' DESC: Set the 32-bit value associated with the specified item in a combo
    ' box.
    ' SYNTAX: success = Combo_SetItemData(hComboBox, index, nData)
    ' NOTES: If the message fails, the return value is %CB_ERR.
    '
    FUNCTION Combo_SetItemData(BYVAL hComboBox AS LONG, BYVAL index AS LONG, BYVAL nData AS LONG) AS LONG
    FUNCTION = SendMessage(hComboBox, %CB_SETITEMDATA, index, nData)
    END FUNCTION


    To Retrieve it:

    '------------------------------------------------------------------------------
    ' TITLE: Combo_GetItemData
    ' DESC: Retrieve the application-supplied 32-bit value associated with the
    ' specified item in the combo box.
    ' SYNTAX: ItemData = Combo_GetItemData(hComboBox, index)
    ' NOTES: The return value is the 32-bit value associated with the item. If
    ' an error occurs, it is %CB_ERR. If -1 is specified for the index,
    ' the current selection is returned.
    '
    FUNCTION Combo_GetItemData(BYVAL hComboBox AS LONG, BYVAL index AS LONG) AS LONG

    IF index < 0 THEN
    index = Combo_GetCurSel(hComboBox)
    END IF

    FUNCTION = SendMessage(hComboBox, %CB_GETITEMDATA, index, 0)

    END FUNCTION


    This was taken from the comctrl.inc file included in PB.



    ------------------
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

    Comment

    Working...
    X