GetEnumerator from custom collection implementing IList is not invokedon datagrid databind

K

kaoskoder

(I posted this earlier in the databind newsgroup with no reaction, i'll
try my luck here :) )

Hi,

I've created a custom collection implementing IList (which implements
ICollection and IEnumerable).
In this collection i want to use a custom enumerator. I would want to
use this to filter the collection on the databind to the control.
Weird thing is that for all of the controls that have datasource
property and databind method, the code gets into the GetEnumerator
method (web and windows forms controls).
But only for the datagrid (both in windows forms and web), it doesn't
invoke the getenumerator of the datasource.

Now, if i implement ICollection instead of IList then the GetEnumerator
gets invoked but only for the webcontrol datagrid (cause the windows
forms datagrid needs the IList interface, it throws error otherwise).

In this code example on msdn where they override the DataBind, they use
the getenumerator of the datasource (which makes me think that in the
initial code it is used the same way) :

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

Almost the only thing i found was this discussion
http://groups.google.be/groups?hl=n...lvNBM7dDHA.2560%40TK2MSFTNGP10.phx.gbl&rnum=1

but that didn't gave me answers either.

Can anyone give me an explanation for this behaviour (/bug)?
Or if anyone can provide me of code that *does* the trick?

I've attached a file with a custom collection and a windows forms which
fills up a datagrid and a listbox with the same collection.
The GetEnumerator gets invoked by the listbox but not by the datagrid
(the same behaviour can be found in webcontrol)




Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.ListBox1 = New System.Windows.Forms.ListBox
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 8)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(328, 216)
Me.DataGrid1.TabIndex = 0
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(8, 232)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(328, 186)
Me.ListBox1.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(344, 429)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Public Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Try

Dim _context As New IHC.Global.Context.UserContext
Dim _pc As New IHC.WorkClasses.CPD.PersonCollection(_context)
_pc.SelectPersons(_context)
Me.ListBox1.DataSource = _pc
Me.DataGrid1.DataSource = _pc
Dim _p As IHC.WorkClasses.CPD.Person = CType(_pc.Item(0), IHC.WorkClasses.CPD.Person)
_p.firstname = "Johnny"
Dim _ec As IHC.Global.ErrorCollection = _p.Persist(Nothing, _context)
If _ec.IsInError Then
MessageBox.Show("error")
End If

Catch ex As Exception
MessageBox.Show(ex.Message & ex.StackTrace & ex.Source)
End Try
End Sub

End Class
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top