Home Forums WinForms controls Xceed Grid for WinForms Xceed Grid + SmartToolbar = System.Reflection.TargetInvocationException

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16111 |

    I have setup a simple form with the following controls via code:

    1. XCeed Grid

    2. Xceed Validator

    3. Xceed Winbutton

    4. Xceed Toolbar menu

    The program has been setup to retrieve a business object and being bind to the grid.  Validator has also been setup and is functional (at least, it picks up any cells failing the validation provider).

    The command button will end any modification and save the changes. 

     When I click on the winbutton, everything worked just fine.  It finalised any changes and updates to the underlying database. 

    With the toolbar menu, I have setup a tool to perform exactly the same actions as the command button.  However, with everything remaining the same as before, except moving the saving action to the smarttool.  It ended up with System.Reflection.TargetInvocationException error and halts in debug mode.  I have attempted to search for a possible cause, but I failed terribly.  Anyone able to shed some lights on this?  Anything that may have caused such error?

    Imported from legacy forums. Posted by James (had 1532 views)

    Xceed Support
    Member
    Post count: 5658

    Could we have the call stack of the of the exception? And could you activate the “break on all exception” parameter in Visual Studio? After, we’ll be able to help you further.

    Imported from legacy forums. Posted by CharlesB (had 1861 views)

    User (Old forums)
    Member
    Post count: 23064

    Sub Routine that generated the exception

     Private Sub Tool3_Click(ByVal sender As System.Object, ByVal e As Xceed.SmartUI.SmartItemClickEventArgs) Handles Tool3.Click
            Dim mAllValid As Boolean = True  ‘Variable holding the validation result

            ‘ Completes the insertion row data entry

            If CType(Me.InsertionRow1, Xceed.Grid.InsertionRow).IsBeingEdited Then
                CType(Me.InsertionRow1, Xceed.Grid.InsertionRow).EndEdit()
            End If

            ‘ Hides the Insertion Row

            Me.InsertionRow1.Visible = False

            ‘Validates the current data row in modification and terminates edit mode.

            If TypeOf Me.GridControl1.CurrentRow Is Xceed.Grid.DataRow Then
                If CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow).IsBeingEdited Then

                    ‘ The program failed on the following line
                    mAllValid = mAllValid And Me.Validator.Validate(CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow), True, False)

                    If mAllValid Then CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow).EndEdit()
                End If
            End If

            ‘ If data in grid passed all validation, the object gets saved.

            If mAllValid Then obj.Save()
        End Sub

    Sub Routine that worked perfectly

       Private Sub WinButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WinButton1.Click
            Dim mAllValid As Boolean = True ‘Variable holding the validation result

            ‘ Completes the insertion row data entry

            If CType(Me.InsertionRow1, Xceed.Grid.InsertionRow).IsBeingEdited Then

                CType(Me.InsertionRow1, Xceed.Grid.InsertionRow).EndEdit()
            End If

            ‘ Hides the Insertion Row

            Me.InsertionRow1.Visible = False

            ‘ Validates the current data row in modification and terminates edit mode.

            If TypeOf Me.GridControl1.CurrentRow Is Xceed.Grid.DataRow Then
                If CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow).IsBeingEdited Then
                    mAllValid = mAllValid And Me.Validator.Validate(CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow), True, False)

                    If mAllValid Then CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow).EndEdit()
                End If
            End If

            ‘ If data in grid passed all validation, the object gets saved.

            If mAllValid Then obj.Save()
        End Sub

    Comments 

    I had exactly the same routine in both SmartTool button click and a standard WinButton click, the routine for WinButton click event worked like a charm.  However, the above routine failed the process.  I do not really know the difference between the two types of events as to why it failed in one and worked in another when the content of the two click events are the same. 

    Exception Stack Trace

    System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    Xceed.Validation.ValidationProvider.ValidateGridElement(Object component, Boolean validateChildren, Boolean validateHidden, Object[] ignoredComponents)
    Xceed.Validation.ValidationProvider.Validate(Object component, Boolean validateChildren, Boolean validateHidden)
    Form1.Tool3_Click(Object sender, SmartItemClickEventArgs e) 

    D:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\FMCSMS\GUI\Form1.vb: Line 108
    Xceed.SmartUI.SmartItem.OnClick(SmartItemClickEventArgs e)
    Xceed.SmartUI.SmartItem.InvokeOnClick(SmartItemClickEventArgs e)
    Xceed.SmartUI.SmartControl.InvokeItemClick(SmartItem item, ClickSource clickSource)
    Xceed.SmartUI.SmartControl.OnMouseUp(MouseEventArgs e)
    System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    System.Windows.Forms.Control.WndProc(Message& m)
    System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
    System.Windows.Forms.Form.ShowDialog()
    FMCSMS.GUI.StartUp.Main() 於 D:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\FMCSMS\GUI\StartUp.vb: Line 85

    Inner Exception Stack Trace

    System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
    System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
    System.String.System.IConvertible.ToInt32(IFormatProvider provider)
    System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    Xceed.Grid.Editors.TextEditor.GetControlValueCore(Control control, Cell cell, Type returnDataType)
    Xceed.Grid.Editors.CellEditorManager.GetControlValue(Control control, Cell cell, Type returnDataType)
    Xceed.Grid.Cell.InputValidatorValidate(Delegate validationDelegate, Boolean validateChildren, Boolean validateInvisibleElements, Object[] ignoredElements)
    Xceed.Grid.CellRow.InputValidatorValidate(Delegate validationDelegate, Boolean validateChildren, Boolean validateInvisibleElements, Object[] ignoredElements)
    Xceed.Grid.CellRow.InputValidatorValidateAndSetErrorParameters(Delegate validationDelegate, Boolean validateChildren, Boolean validateInvisibleElements, Object[] ignoredElements, Icon errorIcon, Int32 blinkRate, ErrorBlinkStyle blinkStyle)

    Error Message

    An unhandled exception of type ‘System.Reflection.TargetInvocationException’ occurred in mscorlib.dll

    Imported from legacy forums. Posted by James (had 1560 views)

    User (Old forums)
    Member
    Post count: 23064

    Not certain if anyone did manage to replicate the error or not.  I had a look into the Inner Exception and found the error may have occurred during data type conversion from string to numeric.  Initially, I thought it was just my program that’s playing up.  Thus, I decided to hunt for a simple program from the website.  I added a button and a toolbar to the winform as usual.  I included the following codes in the click event on the tool and button:

      Try
                Dim mAllValid As Boolean = True  ‘Variable holding the validation result

                ‘ Completes the insertion row data entry

                If CType(Me.InsertionRow1, Xceed.Grid.InsertionRow).IsBeingEdited Then
                    CType(Me.InsertionRow1, Xceed.Grid.InsertionRow).EndEdit()
                End If

                ‘ Hides the Insertion Row

                Me.InsertionRow1.Visible = False

                ‘Validates the current data row in modification and terminates edit mode.

                If TypeOf Me.GridControl1.CurrentRow Is Xceed.Grid.DataRow Then
                    If CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow).IsBeingEdited Then

                        ‘ The program failed on the following line
                        mAllValid = mAllValid And ValidationProvider1.Validate(CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow), True, False)

                        If mAllValid Then CType(Me.GridControl1.CurrentRow, Xceed.Grid.DataRow).EndEdit()
                    End If
                End If

                ‘ If data in grid passed all validation, the object gets saved.
            Catch ex As Exception
                Stop
            End Try

    The is very much the same as the code I used in my own proggy. After a few modifications in the data shown in the grid and a click of either the tool button or winbutton, the exact same error occurred.  Based on this, I could only guess that the problem may have been caused by the Validation Provider itself.  As to why it happens, I would have no idea at all. 

    In my program, I am using this configuration as a lookup with one column holding a unique ID key (integer) and another description field with string datatype.  This should be the simplest configuration I could come up with for testing purposes. 

    Hopefully, this may give you some more info on the exception.

    Imported from legacy forums. Posted by James (had 745 views)

    User (Old forums)
    Member
    Post count: 23064

    We would need a sample application reproducing the issue, along with the values you are using which causes this exception.  You can send it to support.

    Imported from legacy forums. Posted by André (had 621 views)

    User (Old forums)
    Member
    Post count: 23064

    Andre,

    I have already sent a copy of the application via email to you and a few screen dumps for your reference. 

    Hopefully, you’ll be able to assist in this.

    Thank you very much.

    Imported from legacy forums. Posted by James (had 689 views)

    User (Old forums)
    Member
    Post count: 23064

    This is a bug, and as been corrected.  It should be available in our next release.

    Imported from legacy forums. Posted by André (had 1542 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.