- Mar 13, 2007
- 37
- 0
- 0
I have a listbox in a form. When the application is run, the user can press a button that adds items to the listbox like this:
private void UpdateRuleList()
{
this.listRules.Items.Clear();
ScriptAction scr;
int i = scripts.scripts.Count;
for (int j = 0; j < i; j++)
{
scr = (ScriptAction)scripts.scripts[j];
this.listRules.Items.Add(scr.RuleName);
}
}
Then I attached the following code to the listbox:
private void listRules_SelectedIndexChanged(object sender, EventArgs e)
{
if (listRules.SelectedIndex != -1)
LoadScript(listRules.Items[listRules.SelectedIndex].ToString());
}
When the program is run, if I click on an item in the listbox, then Loadscript is called, but the highlighting on the item I clicked on in the listbox disapears. If I comment out the call to Loadscript, then the highlighting stays, but I need to call it so that it can update the values of other controls in the window.
I tried calling listRules.Focus(); after the LoadScript, because I thought the control lost focus for some reason, but that didn't change anything. How can I get the highlighting to stay?
private void UpdateRuleList()
{
this.listRules.Items.Clear();
ScriptAction scr;
int i = scripts.scripts.Count;
for (int j = 0; j < i; j++)
{
scr = (ScriptAction)scripts.scripts[j];
this.listRules.Items.Add(scr.RuleName);
}
}
Then I attached the following code to the listbox:
private void listRules_SelectedIndexChanged(object sender, EventArgs e)
{
if (listRules.SelectedIndex != -1)
LoadScript(listRules.Items[listRules.SelectedIndex].ToString());
}
When the program is run, if I click on an item in the listbox, then Loadscript is called, but the highlighting on the item I clicked on in the listbox disapears. If I comment out the call to Loadscript, then the highlighting stays, but I need to call it so that it can update the values of other controls in the window.
I tried calling listRules.Focus(); after the LoadScript, because I thought the control lost focus for some reason, but that didn't change anything. How can I get the highlighting to stay?