Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my event handler firing twice?
    primarykey
    data
    text
    <p>hey guys im having a tough time trying to solve this problem ive been at for 3 hours and still couldn't find out why its doing this... here is the code</p> <pre><code>private void Catagory_SelectionChanged(object sender, SelectionChangedEventArgs e) { int selectedCategoryId = categoryIdList[categoryListBox.SelectedIndex]; client.GetItemsAsync(selectedCategoryId); client.GetItemsCompleted += new EventHandler&lt;GetItemsCompletedEventArgs&gt;(client_GetItemsCompleted); } void client_GetItemsCompleted(object sender, GetItemsCompletedEventArgs e) { itemIdList.Clear(); itemNameList.Clear(); itemNumberList.Clear(); itemDisplayList.Clear(); //Clears the Display List Items if (e.Error == null) { itemIdList = e.ItemIDList; itemNumberList = e.itemNumber; itemNameList = e.Result; for (int i = 0; i &lt; itemIdList.Count; i++) { itemDisplayList.Add(new ItemDisplay { itemNumber = itemNumberList[i], itemName = itemNameList[i] }); } //Populating the listbox controll with the itemDisplaylist... Items.ItemsSource = itemDisplayList; } else { MessageBox.Show("Problem in getting the items list."); } } </code></pre> <p>When i change the category the first time it works perfectly... by perfectly i mean that it calls the function <code>GetItemsAsync(selectedCategoryId)</code> and grabs the results and calls the event handler <code>client_GetItemsCompleted()</code> and the inner working of the event handler works as it is supposed to, it sets the lists with the proper data and displays the itemNumber and the itemName in the list box ... BUT when i change the category again to get different items it doesn't work properly, what it's doing is that it clears the lists and populates the lists as it is supposed to, runs the for loop and populates the listBox called <code>Items</code> but for some reason it goes to the top of the function again and empties all the lists :/ ... please tell my why it's executing the function again .. and when i choose another category again it executes the event handler 3 times and then 4 times and so on .. anyone know why its doing this? i need this fixed for my project :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload