-
Jun 2nd, 2025, 06:21 AM
#1521
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
The problem is in the vsFlexGrid is that when you change the SelectionMode to ListBox (=MultiSelection) the vsFlexGrid don't initialize the current selection as selected rows.
Whereas the VBFlexGrid initializes the current selection as selected rows when you set AllowMultiSelection to True.
It's a dilemma because SelectionMode is by design not changing anything to not have side-effects which the VBFlexGrid has same behavior.
But since in the VBFlexGrid it's an extra property I can be free.
And it would feel like a bug to not initialize the selected rows..
EDIT: If turning off ListBox selection mode in vsFlexGrid will instantly reset SelectedRows to 0. But when turning on it doesn't set. For me that is not consistent.
Yes, you're right. It does seem like a logical bug. However, I think it also gives users an option. I can either have it initialize with no rows selected, or use a single line of code vsflexgrid.Select 1, 1 to select the first row by default.
In VBFlexGrid, I could use RowSelected(1) = False to deselect the initially selected row. But if VBFlexGrid receives focus via a mouse click, it will automatically select the first row again, and this won't trigger the SelChange event.
vsFlexGrid is the exact opposite: receiving focus doesn't automatically select anything. Selecting the first row does trigger the AfterSelChange event.
Since sometimes I need to use it as a ListBox, I checked the standard ListBox control. Its logic is consistent with vsFlexGrid: receiving focus doesn't automatically select anything (ListIndex = -1), and clicking the first row triggers the Click event.
Admittedly, my specific need might be relatively niche. Or can the SelectionMode support a ListBox mode like in vsFlexGrid?
I think VBFlexGrid is already excellent, even more user-friendly than vsFlexGrid. It would be perfect if it could add a LoadArray method.
-
Jun 2nd, 2025, 09:33 AM
#1522
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
Yes, you're right. It does seem like a logical bug. However, I think it also gives users an option. I can either have it initialize with no rows selected, or use a single line of code vsflexgrid.Select 1, 1 to select the first row by default.
In VBFlexGrid, I could use RowSelected(1) = False to deselect the initially selected row. But if VBFlexGrid receives focus via a mouse click, it will automatically select the first row again, and this won't trigger the SelChange event.
vsFlexGrid is the exact opposite: receiving focus doesn't automatically select anything. Selecting the first row does trigger the AfterSelChange event.
Since sometimes I need to use it as a ListBox, I checked the standard ListBox control. Its logic is consistent with vsFlexGrid: receiving focus doesn't automatically select anything (ListIndex = -1), and clicking the first row triggers the Click event.
Admittedly, my specific need might be relatively niche. Or can the SelectionMode support a ListBox mode like in vsFlexGrid?
I think VBFlexGrid is already excellent, even more user-friendly than vsFlexGrid. It would be perfect if it could add a LoadArray method.
Thanks for your feedback. Will put LoadArray on the todo list.
Well, the SelChange event does not fire but the MultiSelChange event will.
Having an extra selection mode "ListBox" could be an idea. Will check. It would need to turn AllowMultiSelection to True automatically when that SelectionMode is selected.
EDIT: I re-checked and receiving the focus does not select anything. So, it's then just the "initialization" is different. And for that I won't introduce a new selection mode which might cause more confusion than anything else.
Last edited by Krool; Jun 2nd, 2025 at 12:42 PM.
-
Jun 2nd, 2025, 11:43 PM
#1523
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
EDIT: I re-checked and receiving the focus does not select anything. So, it's then just the "initialization" is different. And for that I won't introduce a new selection mode which might cause more confusion than anything else.
My testing shows the following:
When AllowMultiSelection = False, I cannot deselect the first row via RowSelected(1) = False during initialization.
When AllowMultiSelection = True, RowSelected(1) = False successfully deselects it. Calling vbflexgrid.SetFocus does not select the first row, but clicking a blank area in the grid with the mouse triggers automatic selection.
 Originally Posted by Krool
Having an extra selection mode "ListBox" could be an idea. Will check. It would need to turn AllowMultiSelection to True automatically when that SelectionMode is selected.
If AllowMultiSelection = True, users can hold Ctrl to select multiple rows. What if I want to allow only single-row selection like a ListBox? I need to set AllowMultiSelection = False and AllowSelection = False.
If it were possible to initialize with focus only on the first cell without selecting the entire row, adding a ListBox mode would indeed be unnecessary.
-
Jun 3rd, 2025, 04:37 AM
#1524
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
My testing shows the following:
When AllowMultiSelection = False, I cannot deselect the first row via RowSelected(1) = False during initialization.
When AllowMultiSelection = True, RowSelected(1) = False successfully deselects it. Calling vbflexgrid.SetFocus does not select the first row, but clicking a blank area in the grid with the mouse triggers automatic selection.
If AllowMultiSelection = True, users can hold Ctrl to select multiple rows. What if I want to allow only single-row selection like a ListBox? I need to set AllowMultiSelection = False and AllowSelection = False.
If it were possible to initialize with focus only on the first cell without selecting the entire row, adding a ListBox mode would indeed be unnecessary.
It's valid to have AllowMultiSelection = True and AllowSelection = False. This gives you a "simple listbox selection style" while if AllowSelection keeps True it's like "extended listbox selection style".
And I confirm there is a bug in the LButtonUp handler to select again even when the hit is nowhere. Will check.
EDIT: I found the bug in the LButtonUp handler. (Only affect when AllowMultiSelection = True)
In fact it's stupid mistake as a bool check for True was missing. Will update later. Thanks again.
Last edited by Krool; Jun 3rd, 2025 at 05:54 AM.
-
Jun 3rd, 2025, 06:57 AM
#1525
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
It's valid to have AllowMultiSelection = True and AllowSelection = False. This gives you a "simple listbox selection style" while if AllowSelection keeps True it's like "extended listbox selection style".
As you described, even with AllowMultiSelection set to True and AllowSelection set to False, users can still hold Ctrl to extend multi-row selection. Only when both properties are set to False does it become a true single-selection mode.
Please retest this behavior. Thank you.
-
Jun 3rd, 2025, 08:23 AM
#1526
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
As you described, even with AllowMultiSelection set to True and AllowSelection set to False, users can still hold Ctrl to extend multi-row selection. Only when both properties are set to False does it become a true single-selection mode.
Please retest this behavior. Thank you.
That's intended behavior.
-
Jun 3rd, 2025, 09:17 AM
#1527
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
That's intended behavior.
So there's still no way to not select any entire row in single-selection mode when initialization is complete? Because when AllowMultiSelection = False, setting RowSelected(1) = False during initialization doesn't take effect (possibly because SelectedRows always remain 0?). Therefore, my only option is to use SelectRange 0, 0 to forcibly select a fixed row during initialization to prevent automatic selection of non-fixed row.
-
Jun 3rd, 2025, 09:51 AM
#1528
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
So there's still no way to not select any entire row in single-selection mode when initialization is complete? Because when AllowMultiSelection = False, setting RowSelected(1) = False during initialization doesn't take effect (possibly because SelectedRows always remain 0?). Therefore, my only option is to use SelectRange 0, 0 to forcibly select a fixed row during initialization to prevent automatic selection of non-fixed row.
SelectedRows only is applicable when AllowMultiSelection is True.
You mean the behavior when AllowSelection is False and AllowMultiSelection is True then SelectedRows can be either 0 or 1?
Currently it can't span beyond single selection but as you pointed out CTRL allows to have SelectedRows > 1.
-
Jun 3rd, 2025, 11:21 AM
#1529
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
SelectedRows only is applicable when AllowMultiSelection is True.
You mean the behavior when AllowSelection is False and AllowMultiSelection is True then SelectedRows can be either 0 or 1?
Currently it can't span beyond single selection but as you pointed out CTRL allows to have SelectedRows > 1.
No, my requirement is simply to avoid automatic selection of the first row (without entire row highlighting) after initialization completes. This is because I need users to manually click the first row to trigger the SelChange event.
I only use two configuration modes:
1. Free Multi-Selection Mode:
AllowSelection = True
AllowMultiSelection = True
2. Single-Row Selection Mode:
AllowSelection = False
AllowMultiSelection = False
The core issue is: when AllowMultiSelection = False, at least one row is forcibly selected and cannot be deselected. This is what truly confuses me.
-
Jun 3rd, 2025, 11:54 AM
#1530
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
No, my requirement is simply to avoid automatic selection of the first row (without entire row highlighting) after initialization completes. This is because I need users to manually click the first row to trigger the SelChange event.
I only use two configuration modes:
1. Free Multi-Selection Mode:
AllowSelection = True
AllowMultiSelection = True
2. Single-Row Selection Mode:
AllowSelection = False
AllowMultiSelection = False
The core issue is: when AllowMultiSelection = False, at least one row is forcibly selected and cannot be deselected. This is what truly confuses me.
Yes, it's like in the MSFlexGrid. When AllowMultiSelection is False the selection is simply Row-RowSel and Col-ColSel. There is no way to deselect something.
So I would need to discuss what's the best behavior when AllowMultiSelection = True and AllowSelection = False.
Either be like it is now, single row selection but can add multiple single row selection via CTRL key or else..
Let me make soon the fix for the LButtonUp handler and we see next. That bug needs to be fixed whatever comes next.
EDIT: Update released.
Last edited by Krool; Jun 3rd, 2025 at 03:35 PM.
-
Jun 3rd, 2025, 09:55 PM
#1531
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
Yes, it's like in the MSFlexGrid. When AllowMultiSelection is False the selection is simply Row-RowSel and Col-ColSel. There is no way to deselect something.
So I would need to discuss what's the best behavior when AllowMultiSelection = True and AllowSelection = False.
Either be like it is now, single row selection but can add multiple single row selection via CTRL key or else..
Let me make soon the fix for the LButtonUp handler and we see next. That bug needs to be fixed whatever comes next.
EDIT: Update released.
I'm pleased to report that I've found a solution! In the IDE, first set:
SelectionMode = FlexSelectionModeFree
AllowSelection = False
AllowMultiSelection = False
Then in the Form_Load event, set:
SelectionMode = FlexSelectionModeByRow
This prevents VBFlexGrid from automatically selecting the first row. Clicking the first row with the mouse now correctly triggers the SelChange event.
Thank you for discussing with me patiently.
EDIT:
After further research, I feel this solution still isn't perfect. While the initial list initialization successfully avoids selecting the entire row, if I set FocusRect = FlexFocusRectNone, the single cell Cell(1,1) appears blue—which looks somewhat odd. And If vbflexgrid.Rows = 1, clicking the column header still select the fixed row.
When reloading the list, I need to handle it like this:
Code:
Private Sub InitializeSelection(ByVal Grid As VBFlexGrid)
On Error Resume Next
AllowSelChange = False
Grid.SelectionMode = FlexSelectionModeFree
Grid.SelectRange 1, 1
Grid.SelectionMode = FlexSelectionModeByRow
AllowSelChange = True
Grid.FocusRect = FlexFocusRectLight
End Sub
Then, before the SelChange event ends:
Code:
VBFlexGrid1.FocusRect = FlexFocusRectNone
Doesn't this seem cumbersome?
Perhaps the simplest approach is to treat Row(1) as a hidden row(.rowheight(1) = 0). After initialization, automatically select this hidden row—even if no data is loaded, the hidden row remains permanently present.
This would perfectly mimic the single-selection behavior of vsFlexGrid.
Last edited by bincong; Jun 4th, 2025 at 04:16 AM.
-
Jun 4th, 2025, 05:35 AM
#1532
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
I'm pleased to report that I've found a solution! In the IDE, first set:
SelectionMode = FlexSelectionModeFree
AllowSelection = False
AllowMultiSelection = False
Then in the Form_Load event, set:
SelectionMode = FlexSelectionModeByRow
This prevents VBFlexGrid from automatically selecting the first row. Clicking the first row with the mouse now correctly triggers the SelChange event.
Thank you for discussing with me patiently.
EDIT:
After further research, I feel this solution still isn't perfect. While the initial list initialization successfully avoids selecting the entire row, if I set FocusRect = FlexFocusRectNone, the single cell Cell(1,1) appears blue—which looks somewhat odd. And If vbflexgrid.Rows = 1, clicking the column header still select the fixed row.
When reloading the list, I need to handle it like this:
Code:
Private Sub InitializeSelection(ByVal Grid As VBFlexGrid)
On Error Resume Next
AllowSelChange = False
Grid.SelectionMode = FlexSelectionModeFree
Grid.SelectRange 1, 1
Grid.SelectionMode = FlexSelectionModeByRow
AllowSelChange = True
Grid.FocusRect = FlexFocusRectLight
End Sub
Then, before the SelChange event ends:
Code:
VBFlexGrid1.FocusRect = FlexFocusRectNone
Doesn't this seem cumbersome?
Perhaps the simplest approach is to treat Row(1) as a hidden row(.rowheight(1) = 0). After initialization, automatically select this hidden row—even if no data is loaded, the hidden row remains permanently present.
This would perfectly mimic the single-selection behavior of vsFlexGrid.
I have an idea.
When AllowMultiSelection is True and AllowSelection is False you have the feature of RowSelected(1) which you can turn to False.
The problem is that shift+ctrl or ctrl adds additional single selections. Hence you don't have the full blown single selection feeling.
For this I have the idea to borrow the AllowBigSelection property (which defaults to True) to control here the behavior in this situation.
Because in that exotic situation the AllowBigSelection is useless as AllowSelection is False.
So, when AllowBigSelection is False I would change the behavior to be single selection always. And ctrl would just toggle between SelectedRows = 0 or 1.
This way you can use RowSelected(1) = False in your initialization.
Of course then you need to use the MultiSelChange event instead of SelChange !!!
-
Jun 4th, 2025, 07:29 AM
#1533
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
I have an idea.
When AllowMultiSelection is True and AllowSelection is False you have the feature of RowSelected(1) which you can turn to False.
The problem is that shift+ctrl or ctrl adds additional single selections. Hence you don't have the full blown single selection feeling.
For this I have the idea to borrow the AllowBigSelection property (which defaults to True) to control here the behavior in this situation.
Because in that exotic situation the AllowBigSelection is useless as AllowSelection is False.
So, when AllowBigSelection is False I would change the behavior to be single selection always. And ctrl would just toggle between SelectedRows = 0 or 1.
This way you can use RowSelected(1) = False in your initialization.
Of course then you need to use the MultiSelChange event instead of SelChange !!!
This is a good idea. I'm looking forward to your release of the update.
Additionally, when the grid contains only one fixed row, clicking that fixed row with the mouse causes the fixed row to be selected. I've devised a workaround to prevent this:
Code:
Private Sub VBFlexGrid1_BeforeMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, Cancel As Boolean)
If Button = 1 Then
If VBFlexGrid1.Rows = 1 Then
If Y <= VBFlexGrid1.CellTop + VBFlexGrid1.RowHeight(0) Then
Cancel = True
End If
End If
End If
End Sub
The side effect is that manual column width adjustment becomes impossible. However, when vbflexgrid.Rows = 1, there’s little point in adjusting column widths anyway.
-
Jun 4th, 2025, 02:58 PM
#1534
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
When AllowMultiSelection is True and AllowSelection is False the AllowBigSelection property now controls the behavior whether multiple single selections can be done via shift+ctrl or ctrl.
When AllowBigSelection is set to False (defaults True) it is not allowed anymore and truly single selection.
That is that .SelectedRows can then return only 1 or 0.
@bincong, be aware that altering via .RowSelected(x) does not raise a MultiSelChange event.
-
Jun 5th, 2025, 12:35 AM
#1535
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
Update released.
When AllowMultiSelection is True and AllowSelection is False the AllowBigSelection property now controls the behavior whether multiple single selections can be done via shift+ctrl or ctrl.
When AllowBigSelection is set to False (defaults True) it is not allowed anymore and truly single selection.
That is that .SelectedRows can then return only 1 or 0.
@bincong, be aware that altering via .RowSelected(x) does not raise a MultiSelChange event.
This is fantastic, thank you!
After thorough testing, I have several follow-up observations:
1. Why does mouse-click selection trigger the MultiSelChange event twice?
Occurs once on mouse press and once on release. Note: When AllowSelection = True, it triggers only once.
2. Is it expected behavior that re-clicking an already selected row triggers MultiSelChange?
When AllowSelection = True, this does not re-trigger the event.
3. Could a BeforeMultiSelChange event be implemented?
Rationale: Setting Cancel = True in BeforeSelChange doesn't affect MultiSelChange. Additionally, Ctrl-click deselection triggers MultiSelChange but not SelChange.
Separately, I've observed anomalous behavior in BeforeSelChange:
When setting Cancel = True to block selection changes, the selection still changed.
Code:
'Test BeforeSelChange
Private Sub Form_Load()
With VBFlexGrid1
.Rows = 10
.Cols = 5
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = False
End With
End Sub
Private Sub VBFlexGrid1_BeforeSelChange(ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
If NewRowSel > 5 Then Cancel = True
End Sub
Clicking the last row unexpectedly selects all rows simultaneously.
-
Jun 5th, 2025, 12:47 AM
#1536
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
This is fantastic, thank you!
After thorough testing, I have several follow-up observations:
1. Why does mouse-click selection trigger the MultiSelChange event twice?
Occurs once on mouse press and once on release. Note: When AllowSelection = True, it triggers only once.
2. Is it expected behavior that re-clicking an already selected row triggers MultiSelChange?
When AllowSelection = True, this does not re-trigger the event.
3. Could a BeforeMultiSelChange event be implemented?
Rationale: Setting Cancel = True in BeforeSelChange doesn't affect MultiSelChange. Additionally, Ctrl-click deselection triggers MultiSelChange but not SelChange.
Separately, I've observed anomalous behavior in BeforeSelChange:
When setting Cancel = True to block selection changes, the selection still changed.
Code:
'Test BeforeSelChange
Private Sub Form_Load()
With VBFlexGrid1
.Rows = 10
.Cols = 5
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = False
End With
End Sub
Private Sub VBFlexGrid1_BeforeSelChange(ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
If NewRowSel > 5 Then Cancel = True
End Sub
Clicking the last row unexpectedly selects all rows simultaneously.
1. There are two styles for enumerating the the selected rows. First via .SelectedRows/.SelectedRow which will catch those rows that are Row/RowSel but the selected flag not yet commited, and the second approach to loop all rows and check for each .RowSelected(x), which will not catch those "temporary selections". The MultiSelChange event is fired two times so that both approaches will work for sure. If you have expensive code in the MultiSelChange event I recommend to set the MultiSelChangeTime property to 50.
2. Yes technically it is correct as this is "single selection multi selection". For this a click on an already selected row needs to clear the selected flag and thus raise a MultiSelChange event because you may move the mouse before releasing and thus move it.
3. Yes when the Row/RowSel does not change SelChange is not fired whereas MultiSelChange is fired on deselection/re-selection.
Need to check if and how possible to add BeforeMultiSelChange event. Can you provide an sample usage ?
EDIT:
The test for BeforeSelChange is working. RowSel is not changing, what keeps changing is the Row. You would need to cancel BeforeRowColChange also to prevent effectively a "selection".
Last edited by Krool; Jun 5th, 2025 at 12:55 AM.
-
Jun 5th, 2025, 01:07 AM
#1537
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
1. There are two styles for enumerating the the selected rows. First via .SelectedRows/.SelectedRow which will catch those rows that are Row/RowSel but the selected flag not yet commited, and the second approach to loop all rows and check for each .RowSelected(x), which will not catch those "temporary selections". The MultiSelChange event is fired two times so that both approaches will work for sure. If you have expensive code in the MultiSelChange event I recommend to set the MultiSelChangeTime property to 50.
2. Yes technically it is correct as this is "single selection multi selection". For this a click on an already selected row needs to clear the selected flag and thus raise a MultiSelChange event because you may move the mouse before releasing and thus move it.
3. Yes when the Row/RowSel does not change SelChange is not fired whereas MultiSelChange is fired on deselection/re-selection.
Need to check if and how possible to add BeforeMultiSelChange event. Can you provide an sample usage ?
EDIT:
The test for BeforeSelChange is working. RowSel is not changing, what keeps changing is the Row. You would need to cancel BeforeRowColChange also to prevent effectively a "selection".
Load the order list in VBFlexGrid1. Whenever a row is selected, load the order details in VBFlexGrid2. The order details allow users to make modifications. After making the modifications, the user presses the CommandButton to save them. If there have been modifications but they haven't been saved, and at this time the multiselchange event is triggered in VBFlexGrid1, I need to ask the user whether to discard the modifications. If the user selects "No", then I should set cancel = true in the beforemultiselchange event.
-
Jun 5th, 2025, 01:56 AM
#1538
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
bincong,
after second thought I will soon make an update as following:
AllowSelection/AllowMultiSelection will soon not enforce anymore possible selection change. (like vsFlexGrid)
As also the MS ListView does not enfore it when turning off MultiSelect property. (to be changed in VBCCR as well, VBCCR ListView <> MS ListView mismatch currently)
AllowMultiSelection will still clear or initialize the selected flags. (though vsFlexGrid only clears)
 Originally Posted by bincong
Load the order list in VBFlexGrid1. Whenever a row is selected, load the order details in VBFlexGrid2. The order details allow users to make modifications. After making the modifications, the user presses the CommandButton to save them. If there have been modifications but they haven't been saved, and at this time the multiselchange event is triggered in VBFlexGrid1, I need to ask the user whether to discard the modifications. If the user selects "No", then I should set cancel = true in the beforemultiselchange event.
But here in your explanation MultiSelChange occurs prior to BeforeMultiSelChange, which is not possible ? Or am I missunderstanding ? Maybe pseudo code would help.
-
Jun 5th, 2025, 02:50 AM
#1539
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
bincong,
after second thought I will soon make an update as following:
AllowSelection/AllowMultiSelection will soon not enforce anymore possible selection change. (like vsFlexGrid)
As also the MS ListView does not enfore it when turning off MultiSelect property. (to be changed in VBCCR as well, VBCCR ListView <> MS ListView mismatch currently)
AllowMultiSelection will still clear or initialize the selected flags. (though vsFlexGrid only clears)
But here in your explanation MultiSelChange occurs prior to BeforeMultiSelChange, which is not possible ? Or am I missunderstanding ? Maybe pseudo code would help.
Sorry, it's my inaccurate expression.
Code:
Private Sub Form_Load()
With VBFlexGrid1
.AllowUserEditing = False
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = True
.AllowBigSelection = False
.RowSelected(.Row) = False
End With
With VBFlexGrid2
.AllowUserEditing = True
.SelectionMode = FlexSelectionModeFreeByRow
.AllowSelection = True
.AllowMultiSelection = True
.AllowBigSelection = True
.RowSelected(.Row) = False
End With
'get data from database
'Load the data array to VBFlexGrid1
Command1.Enabled = False 'the save button
End Sub
Private Sub VBFlexGrid1_MultiSelChange()
If VBFlexGrid1.Row = 0 Then Exit Sub
VBFlexGrid2.Clear FlexClearMovable
VBFlexGrid2.Rows = 1
If VBFlexGrid1.RowSelected(VBFlexGrid1.Row) Then
'Get data from database according to selected row of VBFlexGrid1
'Load the data array to VBFlexGrid2
End If
Command1.Enabled = False
End Sub
Private Sub VBFlexGrid2_AfterEdit(ByVal Row As Long, ByVal Col As Long, ByVal Changed As Boolean)
Command1.Enabled = True
End Sub
'If the BeforeMultiSelChange event exists
Private Sub VBFlexGrid2_BeforeMultiSelChange(ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
If Command1.Enabled = True Then
If MsgBox("Do you want to give up the modification?") = vbCancel Then
Cancel = True
End If
End If
End Sub
But if MultiSelChange triggers twice, BeforeMultiSelChange will also trigger twice.
-
Jun 5th, 2025, 04:00 AM
#1540
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
Sorry, it's my inaccurate expression.
Code:
Private Sub Form_Load()
With VBFlexGrid1
.AllowUserEditing = False
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = True
.AllowBigSelection = False
.RowSelected(.Row) = False
End With
With VBFlexGrid2
.AllowUserEditing = True
.SelectionMode = FlexSelectionModeFreeByRow
.AllowSelection = True
.AllowMultiSelection = True
.AllowBigSelection = True
.RowSelected(.Row) = False
End With
'get data from database
'Load the data array to VBFlexGrid1
Command1.Enabled = False 'the save button
End Sub
Private Sub VBFlexGrid1_MultiSelChange()
If VBFlexGrid1.Row = 0 Then Exit Sub
VBFlexGrid2.Clear FlexClearMovable
VBFlexGrid2.Rows = 1
If VBFlexGrid1.RowSelected(VBFlexGrid1.Row) Then
'Get data from database according to selected row of VBFlexGrid1
'Load the data array to VBFlexGrid2
End If
Command1.Enabled = False
End Sub
Private Sub VBFlexGrid2_AfterEdit(ByVal Row As Long, ByVal Col As Long, ByVal Changed As Boolean)
Command1.Enabled = True
End Sub
'If the BeforeMultiSelChange event exists
Private Sub VBFlexGrid2_BeforeMultiSelChange(ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
If Command1.Enabled = True Then
If MsgBox("Do you want to give up the modification?") = vbCancel Then
Cancel = True
End If
End If
End Sub
But if MultiSelChange triggers twice, BeforeMultiSelChange will also trigger twice.
A BeforeMultiSelChange event is too complex because the Row/RowSel change happened already due that you did not cancel out on BeforeRowColChange/BeforeSelChange.
-
Jun 5th, 2025, 10:46 AM
#1541
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
A BeforeMultiSelChange event is too complex because the Row/RowSel change happened already due that you did not cancel out on BeforeRowColChange/BeforeSelChange.
After testing, I found that to prompt the user before switching selected rows, I can only rely on SelChange. This requires using BeforeRowColChange to ask the user and passing their response via a variable to BeforeSelChange. However:
1. In BeforeRowColChange, popping up a MsgBox:
If the user selects OK, the newly selected row gets reset to an unselected state.
2. BeforeRowColChange cannot detect Ctrl-click deselections.
3. If I Add "VBFlexGrid1.RowSelected(VBFlexGrid1.Row) = True" in MultiSelChange, it seems to solve the previous two problems, but this allows dragging to select multiple rows, causing .SelectedRows > 1.
4. Then I must add the following code in MultiSelChange:
Code:
For i = 1 To VBFlexGrid1.Rows - 1
VBFlexGrid1.RowSelected(i) = False
Next
It feels that the implementation is a bit complicated.
Ultimately, I think using .RowHidden(1) = True remains the simpler approach.
Truly appreciate your help, and apologies for the trouble.
-
Jun 5th, 2025, 02:56 PM
#1542
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
AllowSelection/AllowMultiSelection will soon not enforce anymore possible selection change. (like vsFlexGrid)
As also the MS ListView does not enfore it when turning off MultiSelect property. (to be changed in VBCCR as well, VBCCR ListView <> MS ListView mismatch currently)
AllowMultiSelection will still clear or initialize the selected flags. (though vsFlexGrid only clears)
Update released.
 Originally Posted by bincong
It feels that the implementation is a bit complicated.
Ultimately, I think using .RowHidden(1) = True remains the simpler approach.
Truly appreciate your help, and apologies for the trouble.
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.
Last edited by Krool; Jun 5th, 2025 at 03:07 PM.
-
Jun 5th, 2025, 08:43 PM
#1543
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 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
-
Jun 6th, 2025, 01:07 AM
#1544
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.
-
Jun 6th, 2025, 03:06 AM
#1545
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
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.
OK. Thank you, Krool.
-
Jun 6th, 2025, 05:25 AM
#1546
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
I can hardly find any information about VBFlexGrid on Chinese websites. I think VBFlexGrid is exceptionally well-made, and you're a truly outstanding developer. May I share and promote VBFlexGrid on Chinese platforms? I'll include the GitHub address with explicit credit in all shared content.
-
Jun 6th, 2025, 07:10 AM
#1547
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
I can hardly find any information about VBFlexGrid on Chinese websites. I think VBFlexGrid is exceptionally well-made, and you're a truly outstanding developer. May I share and promote VBFlexGrid on Chinese platforms? I'll include the GitHub address with explicit credit in all shared content.
Sure. Thx as well for valued input.
-
Jun 6th, 2025, 01:03 PM
#1548
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
bincong,
instead of doing .RowHidden(1) = False there is a more elegant solution. (where you see the focus rect when control has focus)
But this works only when you have more than 1 column in the scrollable area. Because then SelChange event is fired. When you have 1 column then .ColSel is always same as .Col and SelChange will not fire in this case.
Code:
With VBFlexGrid1
.SelectRange 1, 1, 1, 1 ' .RowHidden(1) = False
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = False
End With
This works now because due to latest release .AllowSelection and .AllowMultiSelection will not enforce selection according to selection mode anymore. So that the previous .SelectRange 1, 1, 1, 1 stays intact.
Last edited by Krool; Jun 6th, 2025 at 01:07 PM.
-
Jun 6th, 2025, 09:58 PM
#1549
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
bincong,
instead of doing .RowHidden(1) = False there is a more elegant solution. (where you see the focus rect when control has focus)
But this works only when you have more than 1 column in the scrollable area. Because then SelChange event is fired. When you have 1 column then .ColSel is always same as .Col and SelChange will not fire in this case.
Code:
With VBFlexGrid1
.SelectRange 1, 1, 1, 1 ' .RowHidden(1) = False
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = False
End With
This works now because due to latest release .AllowSelection and .AllowMultiSelection will not enforce selection according to selection mode anymore. So that the previous .SelectRange 1, 1, 1, 1 stays intact.
Thank you for providing the solution. I just tested it:
When .Rows = 1, the fixed row becomes selectable, which looks visually odd.
To reload the list, I need to:
1. Switch SelectionMode = Free
2. Execute SelectRange 1,1
3. Switch back to SelectionMode = ByRow
Using .RowHidden prevents the fixed row from ever being selected.
When users click the fixed row, it selects the hidden row and triggers SelChange – this can be interpreted as the user deselecting the current row.
-
Jun 8th, 2025, 02:57 PM
#1550
Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Why when sliding the scroll, it is not reflected in the display of the rows or columns as it does in ucGridplus (Leandro Ascierto's grid), in the same way that you can create treview, in addition I had published the grid with some improvements so that it could be adapted to the main one
-
Jun 8th, 2025, 03:02 PM
#1551
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by lizano diaz
Why when sliding the scroll, it is not reflected in the display of the rows or columns as it does in ucGridplus (Leandro Ascierto's grid), in the same way that you can create treview, in addition I had published the grid with some improvements so that it could be adapted to the main one
Set .ScrollTrack to True.
-
Jun 8th, 2025, 05:06 PM
#1552
Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Thanks,
My dear Krool, if you could reconsider the new properties and functionalities that can be added to vbFlexgrid to make it more robust with my publication: Feb 12th, 2025, 05:25 PM
Join Date
Apr 2021
Posts
46
-
Jun 9th, 2025, 11:41 AM
#1553
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by lizano diaz
Thanks,
My dear Krool, if you could reconsider the new properties and functionalities that can be added to vbFlexgrid to make it more robust with my publication: Feb 12th, 2025, 05:25 PM
Join Date
Apr 2021
Posts
46
I am adversed to further increase the size of a TCELL.
What other additions did you add? I can then evaluate. Thx
-
Jun 9th, 2025, 12:07 PM
#1554
Addicted Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
The treeview mode would be awesome
-
Jun 10th, 2025, 01:37 PM
#1555
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
Included enum FlexHighLightAlwaysFocusRect for the HighLight property. (FlexHighLightAlways is default)
If new enum set and the control does not have the focus then the focus rect is also drawn highlighted. (like vsFlexGrid behavior)
MS(H)FlexGrid does not behave like this. This new enum allows to support both behaviors. (default MS(H)FlexGrid behavior; vsFlexGrid cannot behave like this)
The OCX was also updated. (type lib edit)
-
Jun 13th, 2025, 01:49 AM
#1556
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
It would be perfect if it could add a LoadArray method.
Update released.
Included the generic LoadArray function to load data from a variant or string array. (vsFlexGrid allows only variant array)
It's significantly faster for large arrays instead of doing manually via .TextMatrix.
To note is that RowDim/ColDim/PageDim are one-based values! (like for LBound/UBound; vsFlexGrid uses zero-based values)
Also there are Rows/Cols/Row/Col arguments where you can control the amount to load and where to start. (vsFlexGrid allows no control)
When RestrictRows/RestrictColumns are set to True then .Rows/.Cols cannot be increased/decreased by the function. (default False to match vsFlexGrid)
So, when you have a big grid and you want to replace only a part of the content from an array then you may set RestrictRows/RestrictColumns to True.
The OCX was also updated and jumped to typelib version 1.2
Code:
Object={075212A8-C1CF-444E-939D-F6046CCDBC08}#1.2#0; VBFLXGRD18.OCX
-
Jun 13th, 2025, 02:04 AM
#1557
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by Krool
Update released.
Included the generic LoadArray function to load data from a variant or string array. (vsFlexGrid allows only variant array)
It's significantly faster for large arrays instead of doing manually via .TextMatrix.
To note is that RowDim/ColDim/PageDim are one-based values! (like for LBound/UBound; vsFlexGrid uses zero-based values)
Also there are Rows/Cols/Row/Col arguments where you can control the amount to load and where to start. (vsFlexGrid allows no control)
When RestrictRows/RestrictColumns are set to True then .Rows/.Cols cannot be increased/decreased by the function. (default False to match vsFlexGrid)
So, when you have a big grid and you want to replace only a part of the content from an array then you may set RestrictRows/RestrictColumns to True.
The OCX was also updated and jumped to typelib version 1.2
Code:
Object={075212A8-C1CF-444E-939D-F6046CCDBC08}#1.2#0; VBFLXGRD18.OCX
That's great! I didn't expect the update to be released so soon.
-
Jun 14th, 2025, 04:52 AM
#1558
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Minor tweak.
When the combo mode is 'DropDown' (equivalent to DropDownList) the list box item is now drawn with a focus rect, like normal combo box would do. (via LB_CARETON message)
Otherwise 'Editable' (equivalent DropDownCombo) the LB_CARETON is not send and drawn without focus rect.
According to reactos combo.c this undocumted LB_CARETON is needed because the list box has no focus , but just the capture.
Last edited by Krool; Jun 14th, 2025 at 05:01 AM.
-
Jun 18th, 2025, 09:08 PM
#1559
Junior Member
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hi, Krool
When I select multiple rows and use AddItem to insert a new row after each selected row to duplicate all selected rows, this causes inconsistency between .SelectedRow and .RowSelected. Is this behavior potentially unreasonable?
Code:
With VBFlexGrid1
.Rows = 4
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = True
.AllowMultiSelection = True
.SelectAll
End With
For i = VBFlexGrid1.SelectedRows - 1 To 0 Step -1
j = VBFlexGrid1.SelectedRow(i) + 1
VBFlexGrid1.AddItem "", j
Next
For i = 0 To VBFlexGrid1.SelectedRows - 1
Debug.Print VBFlexGrid1.SelectedRow(i)
Next
'result:1,2,3
For i = 1 To VBFlexGrid1.Rows - 1
If VBFlexGrid1.RowSelected(i) Then Debug.Print i
Next
'result:1,3,5
-
Jun 20th, 2025, 01:58 AM
#1560
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
Hi, Krool
When I select multiple rows and use AddItem to insert a new row after each selected row to duplicate all selected rows, this causes inconsistency between .SelectedRow and .RowSelected. Is this behavior potentially unreasonable?
Code:
With VBFlexGrid1
.Rows = 4
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = True
.AllowMultiSelection = True
.SelectAll
End With
For i = VBFlexGrid1.SelectedRows - 1 To 0 Step -1
j = VBFlexGrid1.SelectedRow(i) + 1
VBFlexGrid1.AddItem "", j
Next
For i = 0 To VBFlexGrid1.SelectedRows - 1
Debug.Print VBFlexGrid1.SelectedRow(i)
Next
'result:1,2,3
For i = 1 To VBFlexGrid1.Rows - 1
If VBFlexGrid1.RowSelected(i) Then Debug.Print i
Next
'result:1,3,5
Fixed. (And other edges fixed)
Thanks for reporting!
Last edited by Krool; Jun 20th, 2025 at 03:00 AM.
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
|