开发者

How to tell when somebody is reading an item from a CollectionBase

开发者 https://www.devze.com 2023-03-14 15:37 出处:网络
I\'m not sure if this is possible using a CollectionBase class.I\'d like to know when somebody is accessing an item in a CollectionBase class.

I'm not sure if this is possible using a CollectionBase class. I'd like to know when somebody is accessing an item in a CollectionBase class.

The final goal is to create a "VirtualMode" (similar to the DataGridView control) that allows me to check and validate the data going out prior to the user getting it.

So what would happen is t开发者_如何学JAVAhey could create a collection of say, 20 objects, internally we modify the IList to contain 20 null objects, then when they attempt to read an item, if it is null, we go to the external data source and read it in at that time. Then we replace the existing null object with the read class and next time they try to access it, they get the cached version.

After typing that out. I wonder if the OnValidate might be the right spot to do that.

Any assistance would be greatly appreciated.

Trevor Watson


It's not possible with a CollectionBase. OnValidate() is only called prior to OnInsert(),OnRemove(), and OnSet().

You can inherit from ArrayList and override the indexer property (ArrayList.Item).


Looks like you're looking for a virtualizing collection. This article on CodeProject has a nice implementation (it's intended for data binding in WPF, but it can probably be used in another context)

0

精彩评论

暂无评论...
验证码 换一张
取 消