Automatically recognize and handle changes of an Item in a "System.Collections.ObjectModel.Collectio

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, I wanted to create a custom control with a custom Item-Collection in it. (Similar to the ListView Items, but with other properties) I wrote a Class that holds properties of a single Item data (ClassItemData) and another class that "Inherits System.Collections.ObjectModel.Collection(Of
ClassItemData)". The Collection class contains a public event (ItemCollectionChanged) which is raised when "ClearItems", "InsertItem", "RemoveItem" or "SetItem" is called. (I used "Overrides" on all these functions and added the Raise Event to them.) The event
is handled in the custom control itself and causes the control to refresh/repaint itself. The collection class contains also "Default Public Overloads ReadOnly Property Item(ByVal index As Int32) As ClassItemData" which returns the Item at the speciefic index.
The control refreshes itself when I place the control on a form and use code like: ControlName.Items.Add("TestItem") Unfortunately the control does not refresh itself when I use: ControlName.Items.Item(0).Visible = False The value of the Item itself has changed
after this, but the control does know about the changes and does not refresh itself. If I do a manual repaint/refresh of the control, it looks all fine, but it does not work automatically. Does anyone know, what I have to add, so I can handle an event or something
in the control when a property in the ItemData class has changed? How do I recognize changes in existing items and raise an event in the custom event?

View the full article
 
Back
Top