
Originally Posted by
Krool
Update released.
I don't fully understand what you want to achieve. Having client callbacks (MsgBox) in those events feels certainly not like a good idea.
Maybe track the selected rows when loading grid2 and when grid1 changes selection check if the selected rows of grid2 are different then at original state and then raise a MsgBox "Will loose modification? Want not to save?" vbYes would then save and then grid2 is loaded with new data of selection of grid1, if vbNo then no save and the same, grid2 is loaded with new data of selection of grid1. The MsgBox should certainly happen before you load the new data that the user still sees what data may get lost.
I had considered the approach you mentioned—placing the MsgBox at the start of MultiSelChange. This would allow users to choose whether to save or discard changes.
However, my envisioned solution offers users three options:
1. Save changes
2. Discard changes without saving
3. Cancel switching the selection in grid1
Scenario example:
If a user, still editing data, accidentally clicks another row in grid1, they could choose "Cancel" to abort the switch and continue editing.
This can be implemented in VBFlexGrid:
Code:
Dim GridChanged As Boolean
Dim SelChange As Boolean
Private Sub Form_Load()
With VBFlexGrid1
.RowHidden(1) = True
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = False
End With
With VBFlexGrid2
.AllowUserEditing = True
End With
End Sub
Private Sub VBFlexGrid2_AfterEdit(ByVal Row As Long, ByVal Col As Long, ByVal Changed As Boolean)
GridChanged = True
End Sub
Private Sub VBFlexGrid1_BeforeRowColChange(ByVal NewRow As Long, ByVal NewCol As Long, Cancel As Boolean)
Dim i%
If GridChanged Then
i = MsgBox("Do you want to save the changes?", vbQuestion + vbYesNoCancel)
If i = vbYes Then
'Save
ElseIf i = vbCancel Then
Cancel = True
End If
End If
SelChange = Cancel
End Sub
Private Sub VBFlexGrid1_BeforeSelChange(ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
Cancel = SelChange
SelChange = False
End Sub
Private Sub VBFlexGrid1_SelChange()
If VBFlexGrid1.Row <= 1 Then Exit Sub
'Load new data into VBFlexGrid2
GridChanged = False
End Sub