|
-
Feb 27th, 2003, 06:02 AM
#1
Thread Starter
Addicted Member
Fields names in Combobox [RESOLVED]
From all the examples I've seen so far in this forum all I get is a static solution like "cbo.Items.Add(drCustomers("CompanyName"))", ie., only use the records in~sde a filed.
Well I'm building a little search function and I want to put the fields in a table to be in the Combobox.
So wich property from a dataset can I use to populate a combobox with the field names of a given table?
Last edited by Zealot; Mar 6th, 2003 at 12:22 PM.
-
Feb 27th, 2003, 12:33 PM
#2
Something like this:
VB Code:
For i=0 To ds.Tables(0).Columns.Count-1
cbo.Item.Add(New ListItem(ds.Tables(0).Columns(i).Caption))
Next
-
Mar 6th, 2003, 11:41 AM
#3
Thread Starter
Addicted Member
Erm, Serge, thank you for the code, I had to put that part of the code into a hold, but I'm back into it again.
But are you sure that code is for VB.Net? Did you test it?
I'm asking this because in vb.net the combobox property "Item" doesn't exist, it's now "Items", and vb.net isn't recognizing the word ListItem (and neither am I).
Also I had to change the line ds.Tables(0).Columns.Count-1 to something like ds.DataTable.Columns.Count - 1.
Haven't tested it yet, but I think it might be the way to work, since it doesn't recognize the "Table(0)" as well.
Edit: Ah well, nevermind, I got it to work. 
Here's the working code:
VB Code:
For i = 0 To ds.DataTable.Columns.Count - 1
cbo.Items.Add(ds.DataTable.Columns(i).Caption)
Next
Thank you once again.
PS: I can see now that the word "Item" is highlighted in blue inside the vbcode tags, but not the "Items" word. I guess it's time we see a [vbnetcode] tag around here. 
Or keep the vbcode and use it for vb.net, and use a new [vb6code] tag for the code we now know.
Last edited by Zealot; Mar 6th, 2003 at 11:58 AM.
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
|