D
Dan
I'd like to change the text inserted in the text portion of a combobox
control whenever the user selects an item from its list: let's say the items
list contains some explanatory text followed by the value to be inserted,
e.g.:
one [1]
two [2]
three [3]
the user can type a value (e.g. "2") or select it from the list: in this
case, I do not want to store "two [2]" but just "2" in the text box. I tried
to do this with the following handler (let's say the combobox is named
_cboTest):
private void _cboTest_SelectionChangeCommitted(object sender,
System.EventArgs e)
{
string s = (string)_cboTest.SelectedItem;
int x = s.LastIndexOf('[');
if (x > -1) _cboTest.Text = s.Substring(x+1, s.Length - 2 - x);
}
the code itself works, but as soon as the text is programmatically set (e.g.
to "2") it is reverted by the framework to the selected item's text (e.g. to
"two [2]"). How can I avoid this?
Thanx guys!
control whenever the user selects an item from its list: let's say the items
list contains some explanatory text followed by the value to be inserted,
e.g.:
one [1]
two [2]
three [3]
the user can type a value (e.g. "2") or select it from the list: in this
case, I do not want to store "two [2]" but just "2" in the text box. I tried
to do this with the following handler (let's say the combobox is named
_cboTest):
private void _cboTest_SelectionChangeCommitted(object sender,
System.EventArgs e)
{
string s = (string)_cboTest.SelectedItem;
int x = s.LastIndexOf('[');
if (x > -1) _cboTest.Text = s.Substring(x+1, s.Length - 2 - x);
}
the code itself works, but as soon as the text is programmatically set (e.g.
to "2") it is reverted by the framework to the selected item's text (e.g. to
"two [2]"). How can I avoid this?
Thanx guys!