CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    simple Questn: How to have enums in Bound CB?

    May this is simple question:
    Suppose the database has a field say Color. It is of integer type and takes values from 0-6.

    I am doing a simple & direct hooking up with Data control and Bound Combo. But since 0-6 mean nothing, i want to have human readable Color names. How can i do it, w/o writing a single line of code myself?

    VB 5.0 , DAO and DataCombo. I know.. the technology is old:-). Just investigating...

    By writing some code, it is easy. I was wondering if it is possible to do it automatically.

    Ravi Kiran


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: simple Questn: How to have enums in Bound CB?

    w/o writing a single line of code?
    well, w/o writing a single line of VB code may be.
    create a table "colors" that assigns a human-readable name to all color values and change your SELECT statement to join with that table.
    e.g.
    create table colors(colorvalue int, colorname varchar(20)
    0 - red
    1 - blue
    and so on

    know what I mean?


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: simple Questn: How to have enums in Bound CB?

    Yeah.. After that.. what?

    Ok. Lets create a new table with the color ids and names. How do i make them appear in the combo? How do i make the combo select the color for a exising value of the Color field in the original table? Suppose if i change the color and click the "Next" record btn ('>') of the Data control how to make it update the database table with the new selection?

    In case i confused you: here is what i mean:
    Assume you have a DB already. Also lets say it has 2 tables. DataTable1 and DataTable2
    DataTable1 has a ColorField which is linked to DataTble2 ( this one has color ids and names)
    and a some text fields.

    Put a data control in a form and hook it up to this DB and DataTable1 (recordset). Take a simple text box. Hook the datafield to some text field of this recordset. & Run.

    When you click on the "Next >" / "Back <" btns of the Data control you will browse thru the records.

    If you change the the text in the TB and click "<"/">" the data is automatically validated and recordset updated, if the data control's ReadOnly property is False.

    So, i managed to change the DB w/o writing a single line of code. Right.

    so, AS long as i just do default stuff, i dont need / shouldn't need (?!) to write code myself.

    Now, in this Color ids case also, the values in the color field should be from 0-6 only. So i should provide Drop-down type combo. It has ListField, DataField. DataSource and RowSource.
    I think with appropriate linking this should allow us to get the names from DataTable2 put it in the list. After User changes, get the id back (from DataTabe2) and update the original table (DataTable1, in this case).

    Is this kind of thing possible w/o writing any code ourselves??

    Ravi Kiran

    ps: Yeah, VB code only:-)


  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: simple Questn: How to have enums in Bound CB?

    >In case i confused you
    ... you did :-)
    Sorry, I don't even understand what the problem is.


  5. #5
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: simple Questn: How to have enums in Bound CB?

    I am giving up!!!!!


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

Featured