ba272
asked on
SelectedIndexChanged is firing twice for a ListView
Hi,
I need to be notified when the user changes a ListView selection. Am I handling the right event?
The event gets fired twice for some reason, and I can't find the problem. So I thought I'd be smart and use a boolean variable to call my code once, but not the second time. The code commented out shows my failed attempt to hack a solution.
Any ideas?
Thanks,
Bob
private bool intializingDeliveryRun = true;
private void driverRunsLV_SelectedIndex Changed(ob ject sender, System.EventArgs e)
{
//if ( intializingDeliveryRun )
//{
addressListBox.SelectedInd ex = -1;
SelectDriverRun();
intializingDeliveryRun = false;
/*}
else
{
intializingDeliveryRun = true;
}*/
}
I need to be notified when the user changes a ListView selection. Am I handling the right event?
The event gets fired twice for some reason, and I can't find the problem. So I thought I'd be smart and use a boolean variable to call my code once, but not the second time. The code commented out shows my failed attempt to hack a solution.
Any ideas?
Thanks,
Bob
private bool intializingDeliveryRun = true;
private void driverRunsLV_SelectedIndex
{
//if ( intializingDeliveryRun )
//{
addressListBox.SelectedInd
SelectDriverRun();
intializingDeliveryRun = false;
/*}
else
{
intializingDeliveryRun = true;
}*/
}
ASKER
Alex,
I was careful to check to see I was not changing it programmatically. I'm just talking about the user changing ther selection.
I just ran a test and commented out this line:
SelectDriverRun();
and it still calls the function twice.
Thanks for the help,
Bob
I was careful to check to see I was not changing it programmatically. I'm just talking about the user changing ther selection.
I just ran a test and commented out this line:
SelectDriverRun();
and it still calls the function twice.
Thanks for the help,
Bob
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm testing it now. I actually had coded it with a similar hack, and I'm running it to find why that one works.
You can also stop in the debugger and test calling stack.
ASKER
Thanks. I'll keep working it.
Bob
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When is it called twice? When user changes selection? When program sets SelectedIndex?
Notice that all .NET controls raise change events both as result of user actions, and when control state is changed programmatically.