Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObjectListView - how to remove all objects

When I remove Items with objectListViewInstance.Items.Clear(), Objects will just disappear visually as Items, but they are still in objectListViewInstance.Objects collection.

When I try

foreach(object o in objectListViewInstance.Objects)
{
    objectListViewInstance.RemoveObject(o);
}

it ends up with NullPointerException.

Is there any way to remove Objects since there isn't any Objects.Clear() method?

like image 511
jirinovo Avatar asked Jun 01 '26 23:06

jirinovo


2 Answers

According to comments I tried to do

objectListViewInstance.Objects = null;

and it just works fine :)

like image 77
jirinovo Avatar answered Jun 05 '26 01:06

jirinovo


Is there any way to remove Objects since there isn't any Objects.Clear() method?

The intended methods are

objectListViewInstance.ClearObjects();

to clear all objects and

objectListViewInstance.RemoveObject(o);

to remove a specific model object. However, as Sriram pointed out in the comments, don't remove items from a collection while iterating over it.

like image 29
Rev Avatar answered Jun 05 '26 01:06

Rev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!