Call a visual studio event from a different visual studio event ?

Locked Call a visual studio event from a different visual studio event ?

  • Saturday, July 28, 2012 10:47 PM
     
     

    Question How do I call  my_tabledatagridview_validating while I am in the my_tabledatagridview_dataerror sub ?
    I added the addhandler in the my_tabledatagridview_dataerror. What am I missing ?


    '===========================================================================================================
    Public Class Grid_Form
        Private bs As BindingSource
        Private dgv As DataGridView
        Private ds As DataSet
        Private my_column As Integer
        Private my_handle As Boolean
        Private Sub Grid_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            bs = Me.My_TableBindingSource
            dgv = Me.My_TableDataGridView
            ds = Me.EnvelopeDataSet

        end sub

        Private Sub My_TableDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles My_TableDataGridView.DataError
            AddHandler dgv.Validating, AddressOf Me.My_TableDataGridView_Validating
          
     Dim Result As MsgBoxResult = MsgBox("Error.  Your edits could not be committed: " & e.Exception.Message & vbNewLine & vbNewLine & "Click 'Yes' to fix, 'No' to discard the record", MsgBoxStyle.YesNo, "Validation error")
            If Result = MsgBoxResult.Yes Then
                e.Cancel = True
            Else
                e.Cancel = False
            End If

        End Sub

        Private Sub My_TableDataGridView_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles My_TableDataGridView.Validating
           msgbox("we made it from my_tabledatagridview_dataerror")
        End Sub

    end class

     


    Charlie Soroka

All Replies

  • Monday, July 30, 2012 9:47 AM
    Moderator
     
     Answered

    Hi Charlie,

    AddHandler associates an event with an event handler at run time. If you want to call this method, just call method My_TableDataGridView_Validating in My_TableDataGridView_DataError. 

    However,this operation is not recommended.My_TableDataGridView_Validating was called when data is ready to submit but My_TableDataGridView_DataError was called when data is submitted and get  exception or error. So My_TableDataGridView_Validating  will always execute before My_TableDataGridView_DataError. 

    DataGridView.CellValidating:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalidating.aspx

    DataGridView.DataError:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.dataerror.aspx

    If I misunderstood anything, please feel free to let me know.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

    • Marked As Answer by sorokateam Monday, July 30, 2012 4:02 PM
    •  
  • Monday, July 30, 2012 4:02 PM
     
     

    Thank you for your reply, the two links  helped me solve my error routine problem.


    Charlie Soroka