|
-
Jun 2nd, 2025, 03:55 AM
#11
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
 Originally Posted by bincong
Thank you. I just switched from vsFlexGrid to vbFlexGrid, please compare with the same code with vsFlexGrid as follow.
VSFlexGrid1.selectedrows=0 when the LoadData is complete, the first non-fixed row(or the fixed row while no data was loaded) won't be automatically selected even if VSFlexGrid1 get focus.
At this time, VSFlexGrid1.row=1 and VSFlexGrid1.col=1, but the first row won't be highlighted.
Code:
Private Sub Form_Load()
'VSFlexGrid1 serves as a listbox
With VSFlexGrid1
.Rows = 1
.Cols = 11
.SelectionMode = flexSelectionListBox
.AllowSelection = False
End With
'The data of VSFlexGrid1 depends on the selected row of VSFlexGrid1
With VSFlexGrid2
.Rows = 1
.Cols = 6
.SelectionMode = flexSelectionListBox
.AllowSelection = True
End With
Call LoadData
End Sub
Private Sub LoadData()
VSFlexGrid1.Clear 1 'Initialize for grid
VSFlexGrid1.Rows = 1
'----------------------
'Get data from database
'Load the data array to VsFlexGrid1
'----------------------
End Sub
Private Sub VSFlexGrid1_AfterSelChange(ByVal OldRowSel As Long, ByVal OldColSel As Long, ByVal NewRowSel As Long, ByVal NewColSel As Long)
If NewRowSel = 0 Then Exit Sub
VBFlexGrid2.Clear 1
VBFlexGrid2.Rows = 1
'----------------------
'Get data from database according to selected row of VBFlexGrid1
'Load the data array to VBFlexGrid2
'----------------------
End Sub
'Remove seletedrows
Private Sub MenuRemove_Click()
Dim i%
For i = VSFlexGrid2.SelectedRows - 1 To 0 Step -1
VSFlexGrid2.RemoveItem VSFlexGrid2.SelectedRow(i)
Next
End Sub
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.
Last edited by Krool; Jun 2nd, 2025 at 05:31 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
|