I am writing an application, where I fill a combobox with strings and then select a value.
Sometimes, I want to programmatically change to another value, but I cannot get that to work.
Assignments to .Text or .SelectedItem does not work, and even if I start with setting the selectedIndex = -1, it flips back to the old position when I try to set it to the new.
Anyone got any advice?
public void SetString(string name) {
int index = comboBoxtask.FindString(name);
comboBoxtask.SelectedIndex = -1; // this is ok
comboBoxtask.Text = ""; // is already empty, but what the heck
comboBoxtask.Text = name; // reverts back to the old name??
comboBoxtask.SelectedIndex = index; // no change, still old index now even though it is -1 before the text is set
comboBoxtask.SelectedItem = comboBoxtask.Items[index]; // does not work either
}
Sometimes, I want to programmatically change to another value, but I cannot get that to work.
Assignments to .Text or .SelectedItem does not work, and even if I start with setting the selectedIndex = -1, it flips back to the old position when I try to set it to the new.
Anyone got any advice?
public void SetString(string name) {
int index = comboBoxtask.FindString(name);
comboBoxtask.SelectedIndex = -1; // this is ok
comboBoxtask.Text = ""; // is already empty, but what the heck
comboBoxtask.Text = name; // reverts back to the old name??
comboBoxtask.SelectedIndex = index; // no change, still old index now even though it is -1 before the text is set
comboBoxtask.SelectedItem = comboBoxtask.Items[index]; // does not work either
}