Im working on a app for my study. Now i just started a app where i got a database with the soccer league's and the clubs etc. My app has the following features
- Combobox with the league's.
- Listbox that shows the clubs based on your selection from the league.
- Listbox that show the players based on your selection from the clubs.
Now i get this error
System.NullReferenceException: object reference not set to an instance of an object
Now i know why this error is caused because if i select a player it gives some information about the player to labels. But if select a other league in the combobox or a other club in the listbox the selection changed in the player listbox which triggers the event and will try to update the labels but there is no player selected so it will show this error.
Now to fix this error i have no clue what i can do so it wont trigger the event if i already selected a player and try to change club or league.
How the labels are being updated:
private void Listboxspelers_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//set player statistics
lblpositie.Content = "Positie: " + db.GetPositie(listboxspelers.SelectedItem.ToString());
lbldoelpunten.Content = "Aantal Doelpunten: " + db.GetDoelpunten(listboxspelers.SelectedItem.ToString());
lblgelekaarten.Content = "Aantal GeleKaarten: " + db.GetGeleKaarten(listboxspelers.SelectedItem.ToString());
lblRodeKaarten.Content = "Aantal RodeKaarten: " + db.GetRodeKaarten(listboxspelers.SelectedItem.ToString());
}