ItemData: Where is it ? :|

Mikecrosoft
01-19-2004, 04:53 PM
Hi,


I'm using a ComboBox to show information from a DataTable, I need to identify each item from the combo using an ID, before in VB 6.0 I used ItemData when I added the new item, but I can't see how it done in :NET because theres not a ItemData property in the combobox. I need some ideas or show me the right way ?


Thanks

Mike

OnErr0r
01-19-2004, 05:03 PM
Since combobox items are now objects and not just strings, they can contain classes. Your class information could contain an itemdata property. Or, you could inherit the Combobox class and add your own ItemData property.

VBJoe
01-19-2004, 10:11 PM
If you're binding the ComboBox to a data source, you can set the .ValueMember field to signify which field is your ID field, and DisplayMember to show which field is to be displayed in the Combo Box:

Dim sql As String = "SELECT Field1, Field2 FROM SomeTable"

'Code here to get the execute the query and grab a data source:

cboTest.ValueMember = Field1
cboTest.DisplayMember = Field2

'Code here to bind the data source to the ComboBox

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum