Home - Forums-.NET - FlyGrid.Net (Windows Forms) - specified cast not valid

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

specified cast not valid
Link Posted: 07-Sep-2005 21:35
Hi,
Another bug that I don't get with Flygrid 1.0...:

When I open my form I get the exception : Specified cast is not valid.
Call Stack is at the line :

dgParams.Rows.DataSource = m_dsParams

Here's my code although I think it is correct and the issue must be elsewhere. Could you compare your code of 1.0 and 1.2 and try and investigate what are the differences/improvements made that could explain so many bugs ?

And please don't send me any samples as proof that my code should work. It doesn't prove anything since exceptions are raised depending on many factors.

Thank you

  
     PrepareDisplayColumns()
        dgDisplay.Rows.DataMember = m_dsDisplay.Tables(0).TableName
        dgDisplay.Rows.DataSource = m_dsDisplay
        PrepareParamsColumns()
        dgParams.Rows.DataMember = m_dsParams.Tables(0).TableName
        dgParams.Rows.DataSource = m_dsParams
        
        Private Sub PrepareDisplayColumns()
        'desc   : we build the display token fields grid here
        Dim tableloop As Integer
        Dim dtEmp As DataTable

        dtEmp = m_QToken.GetEmptyTable

        dgDisplay.BeginInit()
        dgDisplay.Columns.Items.Clear()

        Dim col As New Column
        col.FitMode = ColumnFitMode.SmartFit
        Dim dc As DataColumn = m_dsDisplay.Tables(0).Columns(tableloop)

        Dim ValueFieldType As New LookupListColumn("View Field Type", "ViewFieldTypeID")
        ValueFieldType.LookupSource = m_dsDisplay.Tables(1)
        ValueFieldType.LookupBoundField = "FieldTypeID"
        ValueFieldType.LookupDisplayField = "FieldType"
        col = ValueFieldType
        dgDisplay.Columns.Items.Add(col)

        Dim ViewTableValue As New LookupListColumn("View Table", "ViewTable")
        ViewTableValue.LookupSource = m_dsSysInfo
        ViewTableValue.LookupBoundField = "table_name"
        ViewTableValue.LookupDisplayField = "table_name"
        col = ViewTableValue
        dgDisplay.Columns.Items.Add(col)

        m_ViewFieldValue = New LookupListColumn("View Field", "ViewField")
        m_ViewFieldValue.LookupSource = dtEmp
        m_ViewFieldValue.LookupBoundField = "New"
        m_ViewFieldValue.LookupDisplayField = "New"
        col = m_ViewFieldValue
        dgDisplay.Columns.Items.Add(col)

        dgDisplay.EndInit()
    End Sub

    Private Sub PrepareParamsColumns()
        'desc   : we build the parameters grid here
        Dim tableloop As Integer
        Dim dtEmp As DataTable

        dtEmp = m_QToken.GetEmptyTable

        dgParams.BeginInit()
        dgParams.Columns.Items.Clear()

        Dim col As New Column
        col.FitMode = ColumnFitMode.SmartFit
        Dim dc As DataColumn = m_dsParams.Tables(0).Columns(tableloop)

        m_ControlField = New LookupListColumn("Control Field", "ControlField")
        m_ControlField.LookupSource = dtEmp
        m_ControlField.LookupBoundField = "Id"
        m_ControlField.LookupDisplayField = "New"
        col = m_ControlField
        dgParams.Columns.Items.Add(col)

        Dim SourceOtherID As New LookupListColumn("Other Source", "SourceOtherID")
        SourceOtherID.LookupSource = m_dsParams.Tables(3)
        SourceOtherID.LookupBoundField = "SourceOtherID"
        SourceOtherID.LookupDisplayField = "ParamSource"
        col = SourceOtherID
        dgParams.Columns.Items.Add(col)

        Dim ParamFieldType As New LookupListColumn("View Field Type", "ViewFieldTypeID")
        ParamFieldType.LookupSource = m_dsParams.Tables(1)
        ParamFieldType.LookupBoundField = "FieldTypeID"
        ParamFieldType.LookupDisplayField = "FieldType"
        col = ParamFieldType
        col.AllowSelect = False
        dgParams.Columns.Items.Add(col)

        Dim ViewTableParam As New LookupListColumn("View Table", "ViewTable")
        ViewTableParam.LookupSource = m_dsSysInfo
        ViewTableParam.LookupBoundField = "table_name"
        ViewTableParam.LookupDisplayField = "table_name"
        col = ViewTableParam
        dgParams.Columns.Items.Add(col)

        m_ViewFieldParam = New LookupListColumn("View Field", "ViewField")
        m_ViewFieldParam.LookupSource = dtEmp
        m_ViewFieldParam.LookupBoundField = "New"
        m_ViewFieldParam.LookupDisplayField = "New"
        col = m_ViewFieldParam
        dgParams.Columns.Items.Add(col)

        Dim OperatorID As New LookupListColumn("OperatorID", "OperatorId")
        OperatorID.FitMode = ColumnFitMode.SmartFit
        OperatorID.DropDownStyle = DropDownStyle.DropDownList
        OperatorID.LookupSource = m_dsParams.Tables(2)
        OperatorID.LookupBoundField = "ParamOperatorID"
        OperatorID.LookupDisplayField = "ParamOperator"
        col = OperatorID
        dgParams.Columns.Items.Add(col)

        Dim OperatorNotCol As New BooleanColumn("Operator Not", "OperatorNot")
        OperatorNotCol.SupportNulls = True
        dgParams.Columns.Items.Add(OperatorNotCol)

        dgParams.EndInit()
    End Sub
Link Posted: 08-Sep-2005 04:57
Please provide me a stack trace of this error
You can embrase problem code into try-catch statement and insert into catch clause two lines of code:

Try
  '... problem code
Catch e As Exception
  System.Diagnostics.Debug.WriteLine("Exception: " & e.Message);
  System.Diagnostics.Debug.WriteLine("Stack Trace: " & e.StackTrace);
End Try

and send me debug output.
PS: Previous problem was in your code:

Dim OperatorID As New LookupListColumn("OperatorID", "OperatorId")
        OperatorID.FitMode = ColumnFitMode.SmartFit
        OperatorID.DropDownStyle = DropDownStyle.DropDownList
        OperatorID.LookupSource = m_dsParams.Tables(2)
        ' <<<--------change "ParamOperatorID" to "ParamOperatorId"
        OperatorID.LookupBoundField = "ParamOperatorID"
        OperatorID.LookupDisplayField = "ParamOperator"
Link Posted: 08-Sep-2005 05:01
No need. Changing OperatorID to operatorId solved this problem too.

I have a similar error in another form, same behaviour as other message (no values selected in list) but this time I can't see any mis-spelling in my variables name, maybe it is related to something else.

From that I guess the version 1.0 was not case-sensitive, which is why it was working. Maybe you could tell me what other improvements have been made to 1.2 so I can 'guess' what is wrong in this other form.

Thank you for the support.
Link Posted: 08-Sep-2005 05:12
Solved. Error in other form was case  sensitive issue, but this time in the stored procedure.

Thank you again.