Results 1 to 3 of 3

Thread: Fields names in Combobox [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member Zealot's Avatar
    Join Date
    Jul 2002
    Location
    Lisboa, Portugal
    Posts
    206

    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.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Something like this:
    VB Code:
    1. For i=0 To ds.Tables(0).Columns.Count-1
    2.     cbo.Item.Add(New ListItem(ds.Tables(0).Columns(i).Caption))
    3. Next

  3. #3

    Thread Starter
    Addicted Member Zealot's Avatar
    Join Date
    Jul 2002
    Location
    Lisboa, Portugal
    Posts
    206
    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:
    1. For i = 0 To ds.DataTable.Columns.Count - 1
    2.         cbo.Items.Add(ds.DataTable.Columns(i).Caption)
    3. 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
  •  



Click Here to Expand Forum to Full Width