Databinding Collections

B

BB

Hey,

CollectionBase has following methods
OnInsertComplete,OnSetComplete,....

When I bind a collection to a datagrid. Is it the datagrid
thats call the OnInsertComplete? Or is it the List.Add
thats calling the OnInsertComplete?

What I don't understand is when OnSetComplete is called
and who is calling it.

Thanks
BB
 
J

Jay B. Harlow [MVP - Outlook]

BB,
As you know CollectionBase implements the IList interface. When you bind
your CollectionBase based object to a DataGrid, the DataGrid will use the
IList interface offered by CollectionBase.

The CollectionBase implementation of IList.Add calls OnInsert, does the add
to CollectionBase.InnerList, then calls OnInsertComplete.

Remember the CollectionBase.List property is simply the IList interface that
the CollectionBase implements. While the CollectionBase.InnerList property
is the contained ArrayList.
When I bind a collection to a datagrid. Is it the datagrid
thats call the OnInsertComplete? Or is it the List.Add
thats calling the OnInsertComplete?
So yes. The DataGrid is calling IList.Add, which is the same as List.Add,
which is calling the OnInsert & OnInsertComplete overridables.

http://msdn.microsoft.com/library/d...sCollectionBaseClassOnInsertCompleteTopic.asp
What I don't understand is when OnSetComplete is called
and who is calling it.
OnSetComplete is called when you use the IList.Item property to set an item
of the CollectionBase. (List.Item).

http://msdn.microsoft.com/library/d...sCollectionBaseClassOnInsertCompleteTopic.asp

Remember all the CollectionBase.On* methods are called as part of the IList
implementation of the CollectionBase. OnValidate is called from multiple.
One easy way to see what is going on is to derived from CollectionBase,
override all the On* methods, put debug.Writeline in each override, create
an instance of this test class, assign it to an IList variable, call all the
methods of the IList variable.

Public Class TestCollection
Inherits CollectionBase

Protected Overrides Sub OnClear()
Debug.WriteLine(Nothing, "OnClear")
End Sub

Protected Overrides Sub OnValidate(ByVal value As Object)
Debug.WriteLine(value, "OnValidate")
End Sub

' override all the On* method like above

End Class

Dim list As IList = New TestCollection
list.Clear
list.Add("item 1")
list.Remove("item 1")
list.Item(0) = "Silly Me"
' call all methods & properties of IList

The above will also show you the order the methods are called.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top