Combo Box Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • orekinbck@yahoo.com.au

    Combo Box Question

    Hi There

    I have a combo box with DropDownStyle = DropDownList

    The user wants a different string to appear in the display rectangle
    than from the strings in the list.

    So for example, the drop down list items might say
    One
    Two
    Three

    Then when I select 'One' and move focus away from the away from the
    combo box, the combo box shows '1' ... (instead of 'one').

    Any ideas? At the moment I am covering the combo box with a text box
    and using SelectedIndex changed event to populate the text box, but I
    was hoping there was a more elegant solution.

    TIA
    Bill

  • Moty Michaely

    #2
    Re: Combo Box Question

    Hey,

    This solution is only right if you want the display change on lost focus
    event:

    Create a class that will be the object added as items to the combo:

    public class Class2

    {

    private int _Value;

    private string _StringValue;


    public Class2(int numericValue, string stringValue)

    {

    this._Value = numericValue;

    this._StringVal ue = stringValue;

    }

    Add getters for the values and override the ToString() method to display
    anything you want...

    (Check the DisplayMember property of the combo box).

    then, set those event handlers..

    private void comboBox1_GotFo cus(object sender, EventArgs e)

    {

    ((ComboBox)send er).DisplayMemb er = "StringValu e";

    }

    private void comboBox1_LostF ocus(object sender, EventArgs e)

    {

    ((ComboBox)send er).DisplayMemb er = "Value";

    }

    Hope this helps,

    - Moty -

    <orekinbck@yaho o.com.au> wrote in message
    news:1119428851 .449403.77740@g 49g2000cwa.goog legroups.com...[color=blue]
    > Hi There
    >
    > I have a combo box with DropDownStyle = DropDownList
    >
    > The user wants a different string to appear in the display rectangle
    > than from the strings in the list.
    >
    > So for example, the drop down list items might say
    > One
    > Two
    > Three
    >
    > Then when I select 'One' and move focus away from the away from the
    > combo box, the combo box shows '1' ... (instead of 'one').
    >
    > Any ideas? At the moment I am covering the combo box with a text box
    > and using SelectedIndex changed event to populate the text box, but I
    > was hoping there was a more elegant solution.
    >
    > TIA
    > Bill
    >[/color]


    Comment

    • orekinbck@yahoo.com.au

      #3
      Re: Combo Box Question

      Thanks Moty

      Comment

      • orekinbck@yahoo.com.au

        #4
        Re: Combo Box Question

        Thanks Moty

        Comment

        • Moty Michaely

          #5
          Re: Combo Box Question

          Welcome.

          <orekinbck@yaho o.com.au> wrote in message
          news:1119487310 .571545.153750@ g44g2000cwa.goo glegroups.com.. .[color=blue]
          > Thanks Moty
          >[/color]


          Comment

          Working...