Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleItemData stores only integers
Description
KeywordsItemData, integer
CategoriesControls, Bug Alerts
 
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

Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated