combo box -- dumb question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laszlo Szijarto

    #1

    combo box -- dumb question

    Is there a way to set a value for an item in a combo box that's different
    than what's displayed?

    So, for example, I'd like to do something like --

    John Smith
    Mike Jones


    but hidden behind each might be an employee id (155, 239).

    When user selects item on the Combo Box, I'd like to extract a hidden ID
    field and use that instead of the name (which is more user-friendly to
    display).

    Thank you,
    Laszlo


  • Eric Cadwell

    #2
    Re: combo box -- dumb question

    Look into the DislpayMember and ValueMember in association with binding the
    control to a DataSource:
    This sample is in the documentation. USState being a class that has two
    string properties (LongName, and ShortName):

    // Populates the list box using DataSource.
    // DisplayMember is used to display just the long name of each
    state.
    ArrayList USStates = new ArrayList();
    USStates.Add(ne w USState("Alabam a", "AL"));
    USStates.Add(ne w USState("Washin gton", "WA"));
    USStates.Add(ne w USState("West Virginia", "WV"));
    USStates.Add(ne w USState("Wiscon sin", "WI"));
    USStates.Add(ne w USState("Wyomin g", "WY"));

    comboBox1.Selec tedValueChanged += new
    EventHandler(Li stBox1_Selected ValueChanged);
    comboBox1.DataS ource = USStates;
    comboBox1.Displ ayMember = "LongName";
    comboBox1.Value Member = "ShortName" ;

    Reading the value on the changed event would look like this:
    string state = (string)comboBo x1.SelectedValu e;

    HTH,
    Eric Cadwell


    "Laszlo Szijarto" <lszijarto@nosp am.mrdoc.cc> wrote in message
    news:bm3p34$js0 $1@sulawesi-fi.lerc.nasa.go v...[color=blue]
    > Is there a way to set a value for an item in a combo box that's different
    > than what's displayed?
    >
    > So, for example, I'd like to do something like --
    >
    > John Smith
    > Mike Jones
    >
    >
    > but hidden behind each might be an employee id (155, 239).
    >
    > When user selects item on the Combo Box, I'd like to extract a hidden ID
    > field and use that instead of the name (which is more user-friendly to
    > display).
    >
    > Thank you,
    > Laszlo
    >
    >[/color]


    Comment

    • Laszlo Szijarto

      #3
      Re: combo box -- dumb question

      Thank you very much.

      Laszlo


      Comment

      Working...