|
-
Nov 25th, 2003, 10:41 AM
#1
Thread Starter
Fanatic Member
object and combobox
Hi,
I've created my own object called customer, and have put them into a collection. How do i go about putting these in a combobox, displaying the name, but also having a key associated with each customer(already there called customerID)
In vb6 i used to put the customerID in the itemData property of a combo box but this doesn't seem to be here for vb.net
Many thanks
nick
-
Nov 25th, 2003, 10:57 AM
#2
Just use DataBinding to the collection. Use the collection as the datasource then set the DisplayMember to the fieldname that you want to be like the text, and the valuemember to the fieldname that you want to be the ItemData type.
VB Code:
ComboBox1.DataSource=CustomerCollection
ComboBox1.DisplayMember="CustomerName"
ComboBox1.ValueMember="CustomerID"
-
Nov 25th, 2003, 11:20 AM
#3
Thread Starter
Fanatic Member
cboSupplier.valuemember = "personID"
gives an error :
cast from type 'Microsoft.visualbasic.collection' to type 'Object()' is invalid.
If i comment that line out then
cboSupplier.displayMember = "companyName"
doesn't seem to work at all :S
How does the combo box know what the object in the collection is?
-
Nov 25th, 2003, 11:30 AM
#4
Are you inheriting or using the throw back to the old vb6 collection? In order for it to bind to the items property correctly then the collection must implement IList which all .NET collections do or at least most of the classes in the System.Collections namespace do. Otherwise I guess you can just loop through your collection and add each one as an item. You may have to override the ToString function to get it to display the right text.
Last edited by Edneeis; Nov 25th, 2003 at 11:34 AM.
-
Nov 25th, 2003, 11:48 AM
#5
Thread Starter
Fanatic Member
that's it! I had it as a standard collection.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|