6
6tc1
Hi all, I would like to create a ComboBox, then use the
SelectedIndexChanged event handler to activate and get the selected
value (not index).
Anyway, I have the following to link the control with the event
handler:
comboBox.SelectedIndexChanged += new
System.EventHandler(listControlValueChanged);
Here is how I add elements:
ArrayList tokenList = parseRangeString(rangeNodeStr);
for (int i = 0; i < tokenList.Count;i++)
{
comboBox.Items.Add(tokenList);
}
I also tried this method of adding the elements:
ArrayList comboBoxCollection = new ArrayList();
for (int i = 0; i < tokenList.Count;i++)
{
ComboBoxElement comboBoxElement = new ComboBoxElement
((String)tokenList,(String)tokenList);
comboBoxCollection.Add(comboBoxElement);
}
comboBox.DataSource = comboBoxCollection;
comboBox.ValueMember = "mValueMemeber";
comboBox.DisplayMember = "mDisplayMember";
But in either of the above cases, my event handler:
private void listControlValueChanged(object sender, System.EventArgs e)
{
ComboBox comboBox = (ComboBox) sender;
Console.Out.WriteLine("change: "+comboBox.Name+ " index: "+
comboBox.SelectedIndex+ " value: "+ comboBox.SelectedValue);
}
always shows null for the SelectedValue, but SelectedIndex works fine.
Any ideas?
Thanks,
Novice
SelectedIndexChanged event handler to activate and get the selected
value (not index).
Anyway, I have the following to link the control with the event
handler:
comboBox.SelectedIndexChanged += new
System.EventHandler(listControlValueChanged);
Here is how I add elements:
ArrayList tokenList = parseRangeString(rangeNodeStr);
for (int i = 0; i < tokenList.Count;i++)
{
comboBox.Items.Add(tokenList);
}
I also tried this method of adding the elements:
ArrayList comboBoxCollection = new ArrayList();
for (int i = 0; i < tokenList.Count;i++)
{
ComboBoxElement comboBoxElement = new ComboBoxElement
((String)tokenList,(String)tokenList);
comboBoxCollection.Add(comboBoxElement);
}
comboBox.DataSource = comboBoxCollection;
comboBox.ValueMember = "mValueMemeber";
comboBox.DisplayMember = "mDisplayMember";
But in either of the above cases, my event handler:
private void listControlValueChanged(object sender, System.EventArgs e)
{
ComboBox comboBox = (ComboBox) sender;
Console.Out.WriteLine("change: "+comboBox.Name+ " index: "+
comboBox.SelectedIndex+ " value: "+ comboBox.SelectedValue);
}
always shows null for the SelectedValue, but SelectedIndex works fine.
Any ideas?
Thanks,
Novice