Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Invalid Cast Exception / Null Ref Exception

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Invalid Cast Exception / Null Ref Exception
Link Posted: 21-Aug-2005 22:43
I tried the Demo Version  (1.0.9  and 1.0.10)

-> Databinding
-> nullable Columns
-> Editmode on (including new rows)

when just clicking around it throws Exceptions (i.e. some DBNulls are not handled)

my Code for Binding (VB)


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'DataBinding etc
        daInstruments.Fill(DsBACA1)
        daCurrencies.Fill(DsBACA1)

        Dim ds As New DataSet
        daInstruments.Fill(ds)
        daCurrencies.Fill(ds)


        fg.Rows.DataSource = ds.Tables(0)
        PrepareColumns(fg)



    End Sub

    Private Sub PrepareColumns(ByVal fg As FlyGrid)

        Dim dt As DataTable = CType(fg.Rows.DataSource, DataTable)

        fg.BeginInit()
        fg.Columns.Items.Clear()

        Dim i As Integer

        For i = 0 To dt.Columns.Count - 1

            Dim dc As DataColumn = dt.Columns(i)
            If Not dc.ColumnName = "id" Then
                fg.Columns.Items.Add(GetColumn(dc))
            End If

        Next i

        fg.EndInit()

    End Sub
    Private Function GetColumn(ByVal dc As DataColumn) As Column

        Dim col As Column

        'parent Column
        If (dc.ColumnName = "currency_id") Then

            Dim pk As LookupListColumn = New LookupListColumn("W?hrung", dc.ColumnName)
            pk.LookupSource = dc.Table.DataSet
            pk.LookupDataMember = "currencies"
            pk.LookupBoundField = "currency_ID"
            pk.LookupDisplayField = "currency"
            pk.Width = 200
            col = pk

        Else

            Dim tc As TypeCode = Type.GetTypeCode(dc.DataType)
            Select Case tc
                Case TypeCode.Boolean
                    col = New BooleanColumn(dc.Caption, dc.ColumnName)
                Case TypeCode.String, TypeCode.Char
                    col = New Column(dc.Caption, dc.ColumnName)
                Case TypeCode.DateTime
                    col = New DateTimeColumn(dc.Caption, dc.ColumnName)
                    col.EditorStyle = EditorStyle.DropDown
                Case TypeCode.Decimal, TypeCode.Single, TypeCode.Double, TypeCode.Int16, TypeCode.Int32, _
                        TypeCode.Int64, TypeCode.UInt16, TypeCode.UInt32, TypeCode.UInt64, TypeCode.Byte
                    Dim numcol As NumberColumn = New NumberColumn(dc.Caption, dc.ColumnName)
                    numcol.NumberType = Type.GetTypeCode(dc.DataType)
                    numcol.TextAlign = ContentAlignment.MiddleRight
                    If (tc = TypeCode.Decimal) Then
                        numcol.FormatString = "C" 'currency
                    ElseIf (tc = TypeCode.Single) Then
                        numcol.FormatString = "P" 'percent
                    Else
                        numcol.EditorStyle = EditorStyle.Spin
                    End If

                    col = numcol
                Case Else
                    col = New Column(dc.Caption, dc.ColumnName)

            End Select

        End If

        Return col

    End Function

am I missing smtg or is there a bug?
Link Posted: 23-Aug-2005 11:14
Probably you have two versions of FlyGrid installed on your machine and one of the versions (oldest) installed to GAC or VS Toolbox.