Listviewitem Inserted But Missing

This is applicable to development using Microsoft Visual Studio 2008 SP1; .NET framework 3.5.

The issue is that some ListViewItem(s) were successfully inserted, but yet seemed to have gone missing.

Further check revealed that it was due to the presence of double instances of the ListView control with the same name, resulted in some ListViewItem(s) inserted to the other duplicated ListView; instead of the one showing on screen.

In this scenario, it happened when the Form, which was the parent to the ListView control, was disposed and a new instance was created. The disposal wasn't quite successful, resulted in presence of the double instances of the ListView control with the same name.

The Form was also a MDI child to another parent Form.

To solution to this issue is to ensure that the disposal of the Form which is the parent to the ListView control is properly disposed off.

In normal circumstances, invoking the 'close' method of the Form will eventually dispose the Form; making way for garbage collector to claim it.

Nonetheless, extra precautions are needed to ensure that all other processes related to the ListView control, such as timer processes are also being disposed off properly.

For instance, if there is a timer process which manipulates the abovementioned ListView control; to dispose the instance of the ListView control properly must be preceded by ensuring that the timer process is completely stopped and disposed first.

This troubleshooting took me almost 1 week to conclude. The conclusion was derived after I performed deliberate measure to ensure atomicity for each ListViewItem insert process.

ListViewItem 1st, 2nd, 3rd were inserted correctly

ListViewItem 4th was inserted but missing; not visible. It was inserted to another instance of ListView object which should have been disposed off earlier.

ListViewItem 5th,6th,7th were inserted correctly and visible.

Similar to ListViewItem 4th, item 8th was inserted but not visible. It was inserted to another ListView object which was supposed to have been disposed earlier.