News:

Build a stunning handcrafted website with IT Acumens

Main Menu

ItemData stores only integers

Started by nandagopal, May 20, 2009, 07:07 PM

Previous topic - Next topic

nandagopal

Someone asked me why their dollars and cents values stored using the ItemData property was returned in only dollars. The reason is ItemData has data type Long. If you store a Single value in it, it will be rounded off.

If you know the order of the items in the ComboBox or ListBox, just keep them in synch with the array so ComboBox1.Item(i) corresponds to DataValue(i).

This won't work if you set the control's Sorted property to True because then the control reorders the items in the list as you add them. In that case, store the real data in an array or collection. Then save the new item's index in the array/collection in the ItemData property. The data corresponding to item ComboBox1.Item(i) will be the_data(ComboBox1.ItemData(i)).

Michael Heie gives this tip for working with sorted controls. After you add a new item to a ListBox or ComboBox, use the NewIndex property to get the newly added item's index in the control and store the data in corresponding ItemData entry.

    Box.AddItem Data
    Box.ItemData(Box.NewIndex) = ItemData