Is there any reason a NullReference exception would be thrown far away from where the error actually occured? Is there a way to fix it?
I’m calling a delete-from-database method in a Button click event, in the click event it then refreshes the Listview. The null reference is because there is no matching ID to delete, but it is thrown on the lvTrucks.Items.Clear() line.
Just wondering if this is normal, because it makes it hard to debug. The exception happened somewhere else entirely.
Thanks
Andrew
See attached
I tried this
lvTrucks.SelectedIndex = -1;
lvTrucks.BeginUpdate();
lvTrucks.Items.Clear();
lvTrucks.Items.EndUpdate();
In many variations but cannot reproduce.
What Wisej build?
Are you using VirtualMode?
Can you reproduce in an isolated sample?
Do you some some async/task operation on the listview?
The bug only throws when you try to call .Clear() with a ListViewItem selected. I can workaround the bug by de-selecting any selected items before calling .BeginUpdate(); and .Items.Clear();
this definitely appears to be a WiseJ bug!
lvTrucks.SelectedIndex = -1;
lvTrucks.BeginUpdate();
lvTrucks.Items.Clear();
Actually, I can generate this error just by calling TrucksToListView(); a second time from another button click. It seems if you select a ListViewItem, and you call the refresh code, it randomly fails.
private void TrucksToListView()
{
lvTrucks.BeginUpdate();
lvTrucks.Items.Clear(); //throws error here
for (int i = 0; i < Trucks.Count; i++)
{
Trucks tk = Trucks[i];
ListViewItem li = new ListViewItem();
li.Text = tk.id.ToString();
li.SubItems.Add(tk.type);
li.SubItems.Add(tk.truckNumber);
li.SubItems.Add(tk.inspectionDueDate.ToString());
li.SubItems.Add(tk.inService);
li.Tag = tk.id; //tag is storing the truck ID.
lvTrucks.Items.Add(li);//add the listitem
}
lvTrucks.EndUpdate();
}
Please login first to submit.