Maybe someone know how ListView pointer is stored/removed at ReadOnly Property ListView in ListViewItem? How is it implemented? I know ListViewItems are stored in ListViewItemCollection which has constructor New(owner as ListView) but I dont know how pointer to ListView is add/remove in ReadOnly Property in ListViewItem...
A:
A ListViewItem has a reference to its containing ListView in a member field. When you add a ListViewItem to a ListView, the ListView updates this member (this occurs within the private function ListView.InsertItems).
The read-only ListView property provides public, but read-only access to this internal member field. (The member field itself is not read-only.)
To learn more, download Reflector and use the Analyze command to track the various functions which can assign the internal listView field. Note that as the listView member is internal and the functions which modify it are private or internal, you should not rely on this implementation in your own code.
itowlson
2009-11-30 01:35:01
Thank you, i see code already but there is something strange for me... at ListView.InsertItems - ListView call Friend Sub ListViewItem.Host and store reference to itself but why Friend Sub Host is not visible public when object ListViewItem is created?
saw
2009-11-30 02:01:54
Because Host is an internal (Friend) method of ListViewItem. Your code never needs to call it: instead ListView calls it for you (from within InsertItems) when you hook up the ListViewItem to the ListView (via the Add method). So there's no need for Host to be public.
itowlson
2009-11-30 02:36:35