Link to home
Start Free TrialLog in
Avatar of ba272
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_SelectedIndexChanged(object sender, System.EventArgs e)
{
//if ( intializingDeliveryRun )
//{
      addressListBox.SelectedIndex = -1;
      SelectDriverRun();            
      intializingDeliveryRun = false;
/*}
else
{
      intializingDeliveryRun = true;
}*/
}
Avatar of AlexFM
AlexFM

To understand what happens it is necessary to have more information.
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.
Avatar of ba272

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
SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ba272

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.
Avatar of ba272

ASKER

Thanks.  I'll keep working it.

Bob
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial