none
System.Reflection.TargetInvocationException in mscorlib.dll RRS feed

  • Question

  • Hi,

    I use Vb Express 2010 - .NET Framework 4 Client Profile, OS : Windows 10 version 1909)!

    when I do a filter on a bindingsource, I have an error

    Dim  BDS_DT as  bindingsource = nothing
    Dim  DT as  datatable =  loadDT(FileName) ' Load DataTable
    BDS_DT = New  BindingSource(DT,Nothing)
    DataGridView1.DataSource =  BDS_DT

    When I perform an operation on a filter that does not give a result, like :

    BDS_DT.Filter = "TYPE = 'FT' AND TYPE ='PLA'"

    I have errors of this type which do not crash the program but which slightly slow down the execution at the time of the filter

    Une exception de première chance de type 'System.Reflection.TargetInvocationException' s'est produite dans mscorlib.dll
    Une exception de première chance de type 'System.ArgumentOutOfRangeException' s'est produite dans System.dll
    Une exception de première chance de type 'System.ArgumentOutOfRangeException' s'est produite dans System.Windows.Forms.dll
    Une exception de première chance de type 'System.Reflection.TargetInvocationException' s'est produite dans mscorlib.dll
    Une exception de première chance de type 'System.ArgumentOutOfRangeException' s'est produite dans System.dll
    Une exception de première chance de type 'System.ArgumentOutOfRangeException' s'est produite dans System.Windows.Forms.dll
    Une exception de première chance de type 'System.Reflection.TargetInvocationException' s'est produite dans mscorlib.dll
    Une exception de première chance de type 'System.ArgumentOutOfRangeException' s'est produite dans System.dll

    By displaying all the errors in the CLR.

    I do the filter on a string type column and not a date type!

    Thanks for your help


    Steeve






    • Edited by Padpanix Thursday, February 20, 2020 5:47 PM a complement
    Thursday, February 20, 2020 5:31 PM

Answers

  • Hello,

    Thank you for your answers.

    The filter "TYPE = 'FT' ET TYPE = 'PLA'" is a simple filter to explain that it does not give a result. (the real filter which makes several lines).

    After several searches, the problem is at the DataGridView1_RowPrePaint.

    The rowPrePaint runs in a loop because of the following code:

            If Projet.FormatStatutSuppr Then
                'Static cpt As Integer = 0
                'cpt += 1
                '  Debug.Print(cpt.ToString)
                Dim Statut As String = ValeurStr(DataGridView1.Rows(e.RowIndex).Cells("STATUT").Value) '.ToString
                ' Debug.Print(Statut)
                DataGridView1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
                Select Case Statut
                    Case "SUPPR"
                        DataGridView1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Gray
                        '  DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = New Font(DGVFont, FontStyle.Italic) ' ralenti de trop
                    Case "BPE"
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGreen
                    Case "REF"
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightPink
                    Case ""
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGray
                    Case Else
                        'DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = New Font(DGVFont, FontStyle.Regular)  ' ralenti de trop
                End Select
            End If
    I changed the code as follows and the problem was resolved.

            If Projet.FormatStatutSuppr Then
                Static cpt As Integer = 0
                cpt += 1
                Debug.Print(cpt.ToString)
                Dim Row As DataGridViewRow = Me.DataGridView1.Rows(e.RowIndex)
                Dim Statut As String = ValeurStr(Row.Cells("STATUT").Value) ' DRV.ValeurStr("STATUT")
                If Statut = "SUPPR" Then
                    Row.DefaultCellStyle.ForeColor = Color.Gray
                Else
                    Row.DefaultCellStyle.ForeColor = Color.Black
                    If Statut = "BPE" Then
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGreen
                    ElseIf Statut = "REF" Then
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightPink
                    ElseIf Statut = "" Then
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGray
                    End If
                End If
            End If



    Steeve

    • Marked as answer by Padpanix Tuesday, February 25, 2020 9:55 AM
    Tuesday, February 25, 2020 9:55 AM

All replies

  • Although this seems odd to have an AND on the same field

    BDS_DT.Filter = "TYPE = 'FT' AND TYPE ='PLA'"

    I would think this instead

    BDS_DT.Filter = "TYPE = 'FT' OR TYPE ='PLA'"

    But that is not the problem. What happens if you do

    BDS_DT.Filter = "TYPE = 'FT'"

    or

    BDS_DT.Filter = "TYPE ='PLA'"

    or place brackets around TYPE e.g. [TYPE] = .. . .

    If none of these work there is an issue someplace else which is not shown.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, February 20, 2020 6:31 PM
    Moderator
  • Although this seems odd to have an AND on the same field

    BDS_DT.Filter = "TYPE = 'FT' AND TYPE ='PLA'"


    Hey, Karen.  OP says he gets the error when the FILTER would return no results, so he's deliberately presenting the example that would definitely produce no results in all circumstances.

    I'm actually pretty sure the whole post is bogus pseudocode this poster has chosen to present instead of the real code.  That's unbelievably bad form by the way, Padpanix - it's literally the same as taking a Matchbox Car to a real auto mechanic and describing the sound your real car makes when you start it.  The uncapitalized type names 'bindingsource' and 'datatable' are screaming that the presented code is total BS.

    My best guess given all the obfuscation here is that you've previously set up a filter on the same DataTable or BindingSource and failed to remove it before re-using the same instance to load a different set of real data.  The last table and filter you loaded probably has a datetime column with the same name as the string you're getting the error on later.

    Thursday, February 20, 2020 8:45 PM
  • Hello,

    Thank you for your answers.

    The filter "TYPE = 'FT' ET TYPE = 'PLA'" is a simple filter to explain that it does not give a result. (the real filter which makes several lines).

    After several searches, the problem is at the DataGridView1_RowPrePaint.

    The rowPrePaint runs in a loop because of the following code:

            If Projet.FormatStatutSuppr Then
                'Static cpt As Integer = 0
                'cpt += 1
                '  Debug.Print(cpt.ToString)
                Dim Statut As String = ValeurStr(DataGridView1.Rows(e.RowIndex).Cells("STATUT").Value) '.ToString
                ' Debug.Print(Statut)
                DataGridView1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
                Select Case Statut
                    Case "SUPPR"
                        DataGridView1.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Gray
                        '  DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = New Font(DGVFont, FontStyle.Italic) ' ralenti de trop
                    Case "BPE"
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGreen
                    Case "REF"
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightPink
                    Case ""
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGray
                    Case Else
                        'DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = New Font(DGVFont, FontStyle.Regular)  ' ralenti de trop
                End Select
            End If
    I changed the code as follows and the problem was resolved.

            If Projet.FormatStatutSuppr Then
                Static cpt As Integer = 0
                cpt += 1
                Debug.Print(cpt.ToString)
                Dim Row As DataGridViewRow = Me.DataGridView1.Rows(e.RowIndex)
                Dim Statut As String = ValeurStr(Row.Cells("STATUT").Value) ' DRV.ValeurStr("STATUT")
                If Statut = "SUPPR" Then
                    Row.DefaultCellStyle.ForeColor = Color.Gray
                Else
                    Row.DefaultCellStyle.ForeColor = Color.Black
                    If Statut = "BPE" Then
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGreen
                    ElseIf Statut = "REF" Then
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightPink
                    ElseIf Statut = "" Then
                        DataGridView1.Item("STATUT", e.RowIndex).Style.BackColor = Color.LightGray
                    End If
                End If
            End If



    Steeve

    • Marked as answer by Padpanix Tuesday, February 25, 2020 9:55 AM
    Tuesday, February 25, 2020 9:55 AM