0

I have a problem that each time i bind a listbox the selected index change event fires and causes errors. Is there any way i can halt this event when binding the listbox.

yahya kh
  • 751
  • 3
  • 11
  • 23
  • Remove handler, bind and then attach handler but i think there is something else wrong which might be causing this, post the code – V4Vendetta Dec 09 '11 at 06:56
  • The answer is: listbox.AddRange(List.ToArray<>); http://stackoverflow.com/questions/905447/how-to-prevent-listbox-selectedindexchanged-event – yahya kh Dec 09 '11 at 07:13

1 Answers1

2

You can do a work around. Keep a bool variable and set it to true while binding the listbox. When the event raises check of the variable is set to true ignore the event and set the variable to false

//something like this
bool isBinding = false;

//when binding
isBinding = true;
listbox.DataBind();

//in the selection change event
if(isBinding)
{
    isBinding = false;
    return;
}
Haris Hasan
  • 29,856
  • 10
  • 92
  • 122