Connecting Tech Pros Worldwide Forums | Help | Site Map

Combo Box Question

orekinbck@yahoo.com.au
Guest
 
Posts: n/a
#1: Nov 17 '05
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
Guest
 
Posts: n/a
#2: Nov 17 '05

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._StringValue = 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_GotFocus(object sender, EventArgs e)

{

((ComboBox)sender).DisplayMember = "StringValue";

}

private void comboBox1_LostFocus(object sender, EventArgs e)

{

((ComboBox)sender).DisplayMember = "Value";

}

Hope this helps,

- Moty -

<orekinbck@yahoo.com.au> wrote in message
news:1119428851.449403.77740@g49g2000cwa.googlegro ups.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]


orekinbck@yahoo.com.au
Guest
 
Posts: n/a
#3: Nov 17 '05

re: Combo Box Question


Thanks Moty

orekinbck@yahoo.com.au
Guest
 
Posts: n/a
#4: Nov 17 '05

re: Combo Box Question


Thanks Moty

Moty Michaely
Guest
 
Posts: n/a
#5: Nov 17 '05

re: Combo Box Question


Welcome.

<orekinbck@yahoo.com.au> wrote in message
news:1119487310.571545.153750@g44g2000cwa.googlegr oups.com...[color=blue]
> Thanks Moty
>[/color]


Closed Thread


Similar C# / C Sharp bytes