I try to access and update ItemData property of a MS-form combobox, design mode, yet the property is not accessible. NewItemID is not accessible either.
I have queried from the internet and found an article, from Microsoft, stating similar problem when migrate from VB6 application into VisualStudio.NET 20056. However, for my scenario, the entire solution is completely created within VisualStudio.NET 2002.
Thank in advance.

Combobox ItemData is not available/accessible
Peter Torr - MSFT
It has disappeared in 2005 but is still available using a class ...
Public Class ComboListClass
Then in your code to add an item to a combobox:Private sName As String
Private iID As Integer
Public Sub New()
sName = ""
iID = 0
End Sub
Public Sub New(ByVal Name As String, ByVal ID As Integer)
sName = Name
iID = ID
End Sub
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal sValue As String)
sName = sValue
End Set
End Property
Public Property ItemData() As Integer
Get
Return iID
End Get
Set(ByVal iValue As Integer)
iID = iValue
End Set
End Property
Public Overrides Function ToString() As String
Return sName
End Function
End Class
Imports Microsoft.VisualBasic.Compatibility.VB6
<combox>.Items.Add(New ComboListClass(<text to display>, <itemdata as int in this case>))
And for retrieval of the itemdata:
Imports Microsoft.VisualBasic.Compatibility.VB6
x = <combox>.SelectedItem.ItemData
bslim
I think you problem is that the combobox control in .net (at least in the later version I'm looking at 2005) does not have an itemdata property.
If I recall (from memory) this was in VB6 as the items could only be text and the itemdata was used to store data associated with the item.
However in .NET the items collection can store any object. With the Tostring property being used to determine what string is displayed but you can add any object to the items collection.
I think the article is probably detailing that the functionality in VB6 had changed to .NET.
Here's an iteresting take on the idea and shows a .NET implementation without the Itemdata property.
http://www.mgbrown.com/PermaLink37.aspx
petedashwood
The functionality in .NET is far more flexible than the VB6 control.
Once you know how it works then you'll realize the power of the .NET approach and how it involves less coding to allow a combobox which is bound to any object.
Ellaboudy
I've read in the online help system, comes with VS.NET 2002, itemdata is available for listbox, hence combobox.
Currently, my comboxbox(es) is loaded with user-defined class, that has 2 properties; 1, default, to exposed the user-friendly string the other, named "ItemData", is to hold the code numbers. However, this implementation consumes too much resource/memory.
In my solution, there are modules containing forms that have more than 1 combobox(es) that holds few thousand entries (few thousand instances of those classes). I want to reduce the amount of immediate memory consumed by my forms by using the combobox based/built-in functions/properties.
Thanks for your response.
allpdoff
You are in essence creating something similar but I suppose the question would be why would you create a class with an itemdata property to hold an item - when you can simply add the item to the collection.
I think adding a tostring override to you objects that you going to be adding to the collection and then simply adding to the items collection is a better approach.
I would think that the itemdata was removed as it is no longer needed now that the items collection can store any object whereas in VB6 the listitems collection could only store strings.
_hbl_
Sorry Spotty, I did not see nor follow the link. The approach is the same, you can add anything you like to a combobox so long as there is a .tostring that returns a string to display when the control needs it.
I had to convert code for someone and there were a lot of ItemData's in it, creating a class that exposed ItemData meant I could keep the code and its comments in a similar condition for the programmers who created it, the only change was the class method on the add item.