I have a ListView that pulls data from a database via class.
I also use listView_SelectionChanged to track the name of selected product.
public void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selected = LstView.SelectedItem as Product;
string prodName = selected.ProductId.ToString();
SelectedProductName.Text = prodName;
}
As you can see, when row of the ListView is selected, I pull the ProductId, store it in string prodName and then assign it to TextBlock SelectedProductName. At this point, when I hit Go! button to RELOAD same list, I get error on line:
string prodName = selected.ProductId.ToString();
That says: System.NullReferenceException: 'Object reference not set to an instance of an object.'