Menus

Hi, I am using Grid Validating event to save/discard changes to my grid.EnableEdit=false; for my grid. The problem is I am able to get away with this Validating event for almost all the cases to save/discard chnages except for when the user clicks on the menus. Is there an event for such a case to make my grid validate itself... Thanks!

9 Replies

AD Administrator Syncfusion Team September 30, 2004 04:40 PM UTC

In your menu handlers, you can call the form''s Validate method to force the last active control to validate itself.


MB Madhavi Balusu September 30, 2004 06:52 PM UTC

Yes, that works. But if the grid validation fails during the menu selection/validation, I want to take the user back to the grid ( and kind of force the user to enter the right values ) and not execute the rest of the menu handler.. In my grid''s validation, I do set e.Cancel = true; and I tried to check this.Validate == false to bail in the menu handler, but that did not seem to work..So the question is how do I communicate to the caller ( Validate() in menu handler ) that the last active control''s Validation has failed? thanks!


AD Administrator Syncfusion Team September 30, 2004 07:14 PM UTC

Are you using CurrentCellValidating to do your validaing in the grid? The code below seemed to work for me. CopyPaste_907.zip
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        If Not Me.Validate() Then
            Me.GridControl1.Focus()
            Return
        End If
        ''do your menu stuff
        MessageBox.Show("Menu stuff")
End Sub

Private Sub GridControl1_CurrentCellValidating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles GridControl1.CurrentCellValidating
        Dim s As String = Me.GridControl1.CurrentCell.Renderer.ControlText
        Dim d As Double
        If Double.TryParse(s, Globalization.NumberStyles.Number, Nothing, d) Then
            If d > 100 Then
                e.Cancel = True
                Me.GridControl1.CurrentCell.ErrorMessage = "must be less than 100"
            End If
        End If
End Sub


MB Madhavi Balusu September 30, 2004 07:59 PM UTC

Hi Clay, That does not help, because: 1) Minor point: I am using c# not VB 2) using Databound grid. 3) not using CurrentCellValidating, instead using grid.validating event ( long story ), which is getting called from this.Validate() in menu handler. Just can''t propagate the validation failed back to menu handler. 4) most importantly, my menu is on 1 form and the grid is on another form. When I set e.Cancel in the grid.Validating event, I want this.validate() in the menu handler on the other form to return false. Thanks!


AD Administrator Syncfusion Team September 30, 2004 08:06 PM UTC

One possible solution is to add a static bool gridOK member to the grid''s form. Handle the grid''s CurrenctCellMoved event and set gridOK = true. In your validate code, set gridOK = false if the validation fails. You should then be able to check this static member in the menu handler on the other form.


MB Madhavi Balusu September 30, 2004 08:20 PM UTC

Yes. But should''nt this.Validate() return false when my grid.Validating() sets e.Cancel = true?


AD Administrator Syncfusion Team September 30, 2004 08:33 PM UTC

Another thought.... Are you calling Form.Validate on the grid''s parent form or on the menu''s parent form?


MB Madhavi Balusu September 30, 2004 08:39 PM UTC

Calling Validate on Menu''s Parent form which in turn calls grid''s validate


AD Administrator Syncfusion Team September 30, 2004 09:00 PM UTC

I cannot get it to work calling the menu''s form''s Validate, but it does seem to work in this sample if I call the grid''s form''s Validate. DataGridTicks_4463.zip

Loader.
Up arrow icon