|
-
Jun 6th, 2025, 01:07 AM
#11
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
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
I see you use RowHidden(1) to have nothing pre-selected and force the user to make a choice.
I think that's a better approach since you can cancel the new single selections.
Cancelling multi-selection will certainly be not possible. So, instead of .RowSelected(1) = False use your .RowHidden(1) = True.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|