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

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)