Best way to enable / disable menu items based on multiple properties

Are there any real strategies for enabling and disabling menu items based on several conditions?

Example. I have an editable grid with menu items "Save" and "Cancel" (and others). When the grid is initially loaded, it checks to see if the user has permission to edit the elements. If the user has permissions, hd can edit the grid. Initially, Save and Cancel are disabled because they are not needed. If the user makes changes, I want both of them to be included. I am currently doing this with what I call the FormMode property. When the user starts editing, he puts the form / grid in the "Dirty" mode, and the "Save" and "Cancel" buttons are turned on. If any editable control is changed, it sets this property (FormMode) to Dirty. If they click the "Save" or "Cancel" button,data is saved and the buttons are disabled again (they are not needed).

My question is: is there a better, more elegant way to handle this on / off with events or other properties? I have the same scenario on dozens of shapes and grids, and it seems like there should be an easier way to handle this. Can the menu items “know” the state of the form / grid and respond automatically? Can I reuse them in several forms?

I'm not sure my question is clear - sorry if not. But it seems that I spend a lot of time so that the menu items can behave correctly depending on the "mode" of the form. I like them to be included only when it was necessary.

grid in initial mode before editing:

grid during / after editing:

Here are the property settings:

 Public Property GridDataMode() As Mayfran.Base.BaseUtilities.FormMode Implements IGridDataMode.GridDataMode
    Get
        Return _GridDataMode
    End Get
    Set(ByVal arg As Mayfran.Base.BaseUtilities.FormMode)
        'if mode is different from previous mode, then continue:
        If _GridDataMode <> arg Then
            _GridDataMode = arg
            Select Case _GridDataMode
                Case FormMode.Initial
                    'nothing to do here
                Case FormMode.Dirty, FormMode.NewRecord
                    barButtonItemSave.Enabled = Editable
                    barButtonItemCancel.Enabled = True
                    barButtonItemSelectAll.Enabled = False
                    barButtonItemDelete.Enabled = False
                    barButtonItemPrint.Enabled = False
                    barButtonItemRefresh.Enabled = False
                Case FormMode.RecordLoaded
                    barButtonItemSave.Enabled = False
                    barButtonItemCancel.Enabled = False
                    barButtonItemSelectAll.Enabled = True
                    barButtonItemDelete.Enabled = Editable
                    barButtonItemPrint.Enabled = True
                    barButtonItemRefresh.Enabled = True
                Case Else
                    Exit Select
            End Select
            RaiseEvent GridModeChanged(arg)
        End If
    End Set
End Property
+4
source share
1 answer

StackOverflow. , , , .

, GridView GridView, / . DataGridView_CellValueChanged. UpdateBalance(), MSDN, . CellValueChanged , CellBeginEdit CellEndEdit.

Click, . , . , Click, .

GridView . . .NET-, / User Forms Excel . , . !

- Jeoffri

0

All Articles