Binding list to a TrueDataGrid problem

Binding list to a TrueDataGrid problem

Old forum URL: forums.lhotka.net/forums/t/1494.aspx


Massong posted on Monday, October 16, 2006

Hi all,

I have a problem with adding new items to a business collection bound to a Component One TrueDataGrid. Whenever the user presses ESC to cancel adding a new item, my application crashes with a StackOverflowException.

The following example creates a simple List and ListItem class and binds them to a grid:

Public Class Form2

 

    ' List

    Private Class List

        Inherits Csla.BusinessListBase(Of List, ListItem)

    End Class

 

    ' ListItem

    Private Class ListItem

        Inherits Csla.BusinessBase(Of ListItem)

 

        Private mText As String = ""

 

        Public Property Text() As String

            Get

                Return mText

            End Get

            Set(ByVal value As String)

                mText = value

            End Set

        End Property

 

        Protected Overrides Function GetIdValue() As Object

            Return Guid.NewGuid

        End Function

 

    End Class

 

    Private mList As New List

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        C1TrueDBGrid1.AllowAddNew = True

        C1TrueDBGrid1.AllowUpdate = True

 

        ' Data binding: dataSource, dataMember, holdFields

        C1TrueDBGrid1.SetDataBinding(mList, "", False)

    End Sub

 

End Class

When I press ESC to cancel adding a new item, the application crashes in the CopyState() method of the UndoableBase class. The exact position is the formatter.Serialize(...) call:

' serialize the state and stack it

Using buffer As New MemoryStream

   Dim formatter As New BinaryFormatter

   formatter.Serialize(buffer, state)

   mStateStack.Push(buffer.ToArray)

End Using

CopyStateComplete()

First I thought it would be a bug in the grid itself, but the following example without business objects works fine:

Public Class Form1

 

    ' List

    Private Class List

        Inherits System.ComponentModel.BindingList(Of ListItem)

    End Class

 

    ' ListItem

    Private Class ListItem

        Private mText As String = ""

 

        Public Property Text() As String

            Get

                Return mText

            End Get

            Set(ByVal value As String)

                mText = value

            End Set

        End Property

 

    End Class

 

    Private mList As New List

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ExportGrid1.AllowAddNew = True

        ExportGrid1.AllowUpdate = True

 

        ' Data binding: dataSource, dataMember, holdFields

        ExportGrid1.SetDataBinding(mList, "", False)

    End Sub

 

End Class

Thanks for help.

Copyright (c) Marimer LLC