Skip to content

ItemData Property

Description

The ItemData property is used to set or retrieve the Long value associated with a List item.

Property Type

Read-write property

Syntax (Visual Basic)

Public Property ItemData( _
    ByVal [Index](#) As Long _
) As Long

Parameters

  • Index: Contains a one-based index of the item data to set or retrieve. The data stored at Index of ItemData corresponds to the item in List with the same Index. Note that ItemData cannot be assigned to index 0.

Remarks

The ItemData property is used to store additional information for each item in the combo box. ItemData can be associated with each item in the List collection. The combo box displays the items in the List collection in its drop-down list.

Note: ItemData cannot be assigned to the List item at index 0.

Example

Combo List Items with Data (Visual Basic)

This sample illustrates how to associate data with the items in the combo box drop-down list.

'Id of Combo box control  
Dim ID_FONT_COMBO = 500  

Dim ToolBar As CommandBar  

'Adds a toolbar  
Set ToolBar = CommandBars.Add("Standard", xtpBarTop)  
With ToolBar.Controls  

    Dim ControlComboFont As CommandBarComboBox  

    'Adds a combo box control  
    Set ControlComboFont = .Add(xtpControlComboBox, ID_FONT_COMBO, "Font: ")  

    'Drop-down list width is 60 pixels  
    ControlComboFont.Width = 60  

    'Add an item to the combo list  
    ControlComboFont.AddItem "Times New Roman", 1  
    'Associate some data with the item and index 1 in the List collection  
    ControlComboFont.ItemData(1) = 14  

    ControlComboFont.AddItem "Arial", 2  
    ControlComboFont.ItemData(2) = 10  

    ControlComboFont.AddItem "Tahoma", 3  
    ControlComboFont.ItemData(3) = 12  

    ControlComboFont.DropDownListStyle = True  

    'Displays the "empty" item in the combo box. No ItemData can be associated with this item.  
    ControlComboFont.ListIndex = 0  

End With  

Dim ControlComboBox As CommandBarComboBox  
Set ControlComboBox = CommandBars.FindControl(, ID_FONT_COMBO)  

If Not ControlComboBox Is Nothing Then  
    Dim iCount As Long  
    For iCount = 1 To ControlComboBox.ListCount  
        Debug.Print "Font: " & ControlComboBox.List(iCount) & ", Size: " & ControlComboBox.ItemData(iCount) & "."  
    Next  
End If

See Also


Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.