Results 1 to 8 of 8

Thread: display 2 fields in a combobox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    display 2 fields in a combobox

    hi,

    is it possible to display 2 fields in a combobox e.g., a code and a description separated by a hyphen.

    Ex. 01 - Accessories

    thanks,
    marivic

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The combobox by default uses the ToString function to display the item text. You can override that on whatever you are using for the items to display whatever you want.

    VB Code:
    1. Public Override Function ToString() as String
    2.   return "Code - Description"
    3. End Function

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145
    hi edneeis,

    sorry but its not quite clear to me how to do it.

    i've created the combobox and defined the datasource, datamember, and valuemember at design time. how can i incorporate your code in mine.

    thanks for your time.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    What is the datasource?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145
    im using a dataset. i defined a connection and a dataadapter and generate the dataset at design time.

    can u give me example how to do it using a dataset defined at design time and populating the combo at runtime.

    thanks for being patient with me.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well unfortunately my idea didn't work. First I tried inheriting a datarow to override the Tostring, but that gave me trouble. So then I made a wrapper class that converted a datarow but the combobox doesn't like tabs so columns didn't work. I guess I'd have to ownerdraw the list into columns, but I don't have time for an example of that now.

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    After learning more about OwnerDrawing with the ImageCombo I decided to add the ability to have multiple columns in it. So here is an example project with a combo that is rather access like and can have multiple columns (and images if you want). I can't promise that its bug free but it seems to be working fine.
    Last edited by Edneeis; Oct 19th, 2002 at 07:47 PM.

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is a screen shot:



    This version doesn't have the ability to show column headers yet but I plan on trying to add it.
    Last edited by Edneeis; Oct 19th, 2002 at 07:50 PM.

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