ListView remove item problem. Help please
-
I call this function to remove the last item in a listview in details view. The problem is that the control is on a tab page, and if i call this function before the control has been viewed(ie. before the tab page with this control is shown), this function fails with the inner exception of message "Object reference not set to an instance of an object", and, the regular exception of "unable to create handle". This only happens if the control is not viewed first. Can someone help me out here. public void RemoveLastItem() { int index = Items.Count; try { Items.RemoveAt(index-1); } catch(OutOfMemoryException e){ // Error is caught here!! Why ???? #if DEBUG MessageBox.Show(e.InnerException.Message); MessageBox.Show(e.Message); #endif } catch(NullReferenceException e){ #if DEBUG MessageBox.Show(e.Message); #endif } }