Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by rciszek
It seems to me if it never see's the 2nd call for the ODT_LISTBOX that there is something missing in the code to do this, I have the break on all errors option set and nothing occurs.
It certainly is curious that when I click on a row in the dropdown a value is returned and it is what you would expect from the placement in the list, Again, seems like it has white text on a white background.
Again, can't replicate. For me it's working. So we are stuck.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
Again, can't replicate. For me it's working. So we are stuck.
Dear Krool, I am writing the following to you, in the attached file you have many improvements for VBFlexgrid, it would be excellent if you could adapt it to the latest version of VBFlexgrid and in that way have a new version with excellent features such as themas, progress bar, etc.
Hoping you can consider it viable.
Much obliged
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hi all again!, i hope everything is fine here :-)
A little question
We can format a column this way:
Code:
For i = LBound(TT) To UBound(TT)
xCol = xCol + 1
.Col = xCol
.Text = "Zona" & vbCrLf & TT(i)
.ColWidth(xCol) = 250
.ColAlignment(xCol) = FlexAlignmentCenterCenter
.ColKey(xCol) = "zona" & TT(i)
.ColWidth(xCol) = 2000
.ColFormat(xCol) = "#,###0.00"
Next i
But if i want to format 1 cell of this columns for example with "#,###0.000" (one decimal more), is there an option? or must i use textmatrix with format(value) ?
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by lizano diaz
Dear Krool, I am writing the following to you, in the attached file you have many improvements for VBFlexgrid, it would be excellent if you could adapt it to the latest version of VBFlexgrid and in that way have a new version with excellent features such as themas, progress bar, etc.
Hoping you can consider it viable.
Much obliged
I don't know how so many figures are drawn in it.
Like that circular picture. There is a data share of about 10%.
If the prototype is the same picture, just copy it. Draw another triangle.
If the same elements can be drawn in batches.For example, the function that an interface can display is 20 lines of fixed height.
There is a certain amount of space between each line.
You just need to draw 20 identical figures and set the distance between them.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Can you develop an Excel table space?
Read the width and height of each cell. Background color. Font style.Does each cell have a border line?
I have an exce table with 50,000 rows of data and 15 column fields.The file size is about 2.5mb when I set the color of 8 columns.
The file size becomes 5 MB, and he actually writes data to each cell.
In fact, I want to have a table control like this, which can set the color of each column. After saving the Excel file, the size of the file is almost the same.
Last edited by xiaoyao; Feb 13th, 2025 at 04:19 PM.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
Improved mouse handling of the combo drop-down list to enable auto scroll while mouse move (mouse button must be down) and to commit upon mouse button up instead of mouse button down.
It now feels and behaves more like a real combo box.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
You can also enlarge the drop-down list upon EditSetupWindow event via SetWindowPos (pass SWP_NOMOVE SWP_NOACTIVATE etc.)
Then you see the item while list is dropped down. After the edit you may run an .AutoSize.
Hello Krool,
I would like to enlarge the width of the drop down list of a combo column without modifying the column width of the full grid. How can I get the handle of the list window?
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Eduardo-
Hello Krool,
I would like to enlarge the width of the drop down list of a combo column without modifying the column width of the full grid. How can I get the handle of the list window?
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
I am experiencing that after the user selects something in a combo cell, the grid scroll down to the bottom row.
I already had this issue with another VBFlexGrid and I handled the issue by storing the TopRow and restoring it.
It happens even having no code in any event.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Eduardo-
I am experiencing that after the user selects something in a combo cell, the grid scroll down to the bottom row.
I already had this issue with another VBFlexGrid and I handled the issue by storing the TopRow and restoring it.
It happens even having no code in any event.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
Major performance improvement in the .SelectedRow property. (used in conjunction with the .SelectedRows property)
Sample code for typical usage: (when AllowMultiSelection is True)
Code:
Dim i As Long
For i = 0 To VBFlexGrid1.SelectedRows - 1
Debug.Print VBFlexGrid1.SelectedRow(i)
Next i
The problem was here that the larger the grid and the larger the selection an exponential performance issue appears.
Now whenever .SelectedRows is called an indices array (cache) is created and when that cache exists it will be used on .SelectedRow which makes the exponential factor then irrelevant.
If no cache exists then .SelectedRow works as before.
When a cache already exists upon call on .SelectedRows then the cache is untouched.
Whenever the selection changes and the cache exists it will be erased and only re-created upon next call on .SelectedRows.
EDIT:
For info. Of course one can loop all rows and test if .RowSelected(i) returns True. Above mechanism was just adopted from vsFlexGrid and the weakness of that mechanism got fixed now.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Hello, I'm seeing an issue with the scroll bar of the combos. If one does a mouse down over the scroll bar of the combo (in order to start scrolling), and then the mouse goes out of the scroll bar, may be to the left over the combo or to the right over the grid, when you finished scrolling and do the mouse up, the combo list hides.
Another thing: is anyway possible to have an "ItemData" for the combo list?
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Eduardo-
Hello, I'm seeing an issue with the scroll bar of the combos. If one does a mouse down over the scroll bar of the combo (in order to start scrolling), and then the mouse goes out of the scroll bar, may be to the left over the combo or to the right over the grid, when you finished scrolling and do the mouse up, the combo list hides.
Another thing: is anyway possible to have an "ItemData" for the combo list?
Update released. The capture is fixed for the scrollbar. Thanks.
We have the multi-column drop-down list where the ColLookup maps between ID and string. The BoundColumn property defines what column is the string for display.
What use-case would be the "ItemData" ? What code you imagine to use ?
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
What use-case would be the "ItemData" ? What code you imagine to use ?
The use is to have a data associated to a selected list item. Usually it is a number that identifies the item.
For example:
Column "Select city", with these items:
Rome
Munich
Berlin
Paris
London
Madrid
But in the database each city is identified by a number, like 23, 45, 76, 88, 12, etc.
If the user selects Paris, we could want to store 88, not "Paris" as the user selection.
I have thought that as you have ColComboItems that defines the list with items separated by "|", you could also have ColComboItemsData and they could also be strings separated by "|".
There should be then a way to retrieve that selection, some other property I guess.
But anyway I should study what you said about multi-column, maybe it is already possible in another way.
I already have that issue solved in a couple of grids that I added to the current program so far, but I had to do this (let's continue with the example of selecting cities):
Store two arrays:
Code:
mCities_Names() As String
mCities_IDs() As Long
Then in the AfterEdit event of the grid, check the text of the cell that was selected against all the list:
Code:
Private Sub VBFlexGrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long, ByVal Changed As Boolean)
Dim iSelectedCityText As String
Dim c As Long
If Col = 5 Then ' select city column
iSelectedCityText = VBFlexGrid1.TextMatrix(Row, Col)
For c = 0 To UBound(mCities_Names)
If mCities_Names(c) = iSelectedCityText Then
VBFlexGrid1.RowData(Row) = mCities_IDs(c)
Exit For
End If
Next
End If
End Sub
(I actually didn't use RowData because I needed to store several combo selections, so I used hidden columns, but I did now to simplify the sample)
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Eduardo-
The use is to have a data associated to a selected list item. Usually it is a number that identifies the item.
For example:
Column "Select city", with these items:
Rome
Munich
Berlin
Paris
London
Madrid
But in the database each city is identified by a number, like 23, 45, 76, 88, 12, etc.
If the user selects Paris, we could want to store 88, not "Paris" as the user selection.
I have thought that as you have ColComboItems that defines the list with items separated by "|", you could also have ColComboItemsData and they could also be strings separated by "|".
There should be then a way to retrieve that selection, some other property I guess.
But anyway I should study what you said about multi-column, maybe it is already possible in another way.
I already have that issue solved in a couple of grids that I added to the current program so far, but I had to do this (let's continue with the example of selecting cities):
Store two arrays:
Code:
mCities_Names() As String
mCities_IDs() As Long
Then in the AfterEdit event of the grid, check the text of the cell that was selected against all the list:
Code:
Private Sub VBFlexGrid1_AfterEdit(ByVal Row As Long, ByVal Col As Long, ByVal Changed As Boolean)
Dim iSelectedCityText As String
Dim c As Long
If Col = 5 Then ' select city column
iSelectedCityText = VBFlexGrid1.TextMatrix(Row, Col)
For c = 0 To UBound(mCities_Names)
If mCities_Names(c) = iSelectedCityText Then
VBFlexGrid1.RowData(Row) = mCities_IDs(c)
Exit For
End If
Next
End If
End Sub
(I actually didn't use RowData because I needed to store several combo selections, so I used hidden columns, but I did now to simplify the sample)
Use the ColLookup feature. It translates between ID and string.
And it works for normal combo list or multi-column combo list.
The demo project makes use of this to demonstrate it.
You are using VBFLXGRD16.OCX. You may upgrade to VBFLXGRD18.OCX
Hello, I'm still experiencing the issue (with the current version) but when in the BeforeEdit event, the Cancel parameter is set to True.
Also, I have a grid even having the issue without setting the Cancel parameter to True, and even with no code on any event of the grid, but I need to find out what other thing I'm doing differently with that grid.
But maybe it is also the same root cause of setting the Cancel parameter to True, so I'm already reporting the issue.
Anyway I'll try to see what property or configuration I'm doing different with this grid to have the issue back. Thanks.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
OK, I identified other situations besides Cancel = True in the BeforeEdit event:
2) Setting CellComboCue without setting ColComboMode.
3) Showing a modal form in BeforeEdit event, the grid scrolls to the bottom temporarily, while the form is displayed.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Eduardo-
OK, I identified other situations besides Cancel = True in the BeforeEdit event:
2) Setting CellComboCue without setting ColComboMode.
3) Showing a modal form in BeforeEdit event, the grid scrolls to the bottom temporarily, while the form is displayed.
Samples attached. Thank you very much.
I identified the issue. Problem is in the WM_LBUTTONUP handler.
Your .Row is in the bottom and this handler scrolls it into view. It is intended to be like this but of course there are exceptions.
The handler is missing checking the capture result.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
Bugfix in the internal ProcessLButtonUp handler that it can scroll unintentionally when the focused cell is out of view and clicking on a combo cue / fixed cell checkbox etc.
.SelectedRows and .SelectedRow property enhanced to include the selection range while mouse drag move. (inverted or not)
While mouse drag move the selected state is not yet commited but will be upon LButtonUp.
Of course the AllowMultiSelection property must be set to True.
Next would be to include a MultiSelChange event (todo) that for example a total can be displayed to the user while multi-selecting. (like in Excel the sum in the status bar)
In that future MultiSelChange it will then be recommended to use .SelectedRows/.SelectedRow over .RowSelected. (to include that not yet commited selection range)
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
Included the MultiSelChange event which occurs when the selection of multiple (non-contiguous) ranges of cells changes.
Of course the AllowMultiSelection property must be set to True.
Included the MultiSelChangeTime property to set the time in milliseconds before the MultiSelChange event is fired by a window message after a change in the multi-selection. A value of 0 indicates that it is fired immediately.
The timer is reset upon each received window message. The default value is 0. It is recommended, when using the event, to change the property to a value of 50 to have a good performance and to avoid bottlenecks when doing a mouse drag move selection or repeatedly pressing arrow keys or page down etc.
When the change of the multi-selection was via code the MultiSelChange event is always fired immediately.
Example use-case to show a total of the currently selected rows: (like in Excel having a sum in the statusbar)
Code:
Private Sub VBFlexGrid1_MultiSelChange()
Dim Sum As Double, i As Long
' Recommended method as it will include the mouse drag move selection. (inverted or not)
For i = 0 To VBFlexGrid1.SelectedRows - 1
Sum = Sum + VBFlexGrid1.TextMatrix(VBFlexGrid1.SelectedRow(i), 1)
Next i
' Alternative approach but without temporary mouse drag move selection.
'For i = .FixedRows To VBFlexGrid1.Rows - 1
' If VBFlexGrid1.RowSelected(i) = True Then
' Sum = Sum + VBFlexGrid1.TextMatrix(i, 1)
' End If
'Next i
Label1.Caption = Sum
End Sub
The OCX was also updated and jumped to typelib version 1.1
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Update released.
The default value for the MultiSelChangeTime property changed to 0. On second thought this makes more sense, because most probably one would not use this event at all. And then why by default polluting the window with additional WM_TIMER messages..
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
does anyone have an example of using the datasource property of a flexgrid within twin basic ? i'm not for sure thats possible at this time. the data control within twinbasic appears incomplete.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
Update released.
Included the MultiSelChange event which occurs when the selection of multiple (non-contiguous) ranges of cells changes.
Of course the AllowMultiSelection property must be set to True.
Included the MultiSelChangeTime property to set the time in milliseconds before the MultiSelChange event is fired by a window message after a change in the multi-selection. A value of 0 indicates that it is fired immediately.
The timer is reset upon each received window message. The default value is 0. It is recommended, when using the event, to change the property to a value of 50 to have a good performance and to avoid bottlenecks when doing a mouse drag move selection or repeatedly pressing arrow keys or page down etc.
When the change of the multi-selection was via code the MultiSelChange event is always fired immediately.
Example use-case to show a total of the currently selected rows: (like in Excel having a sum in the statusbar)
Code:
Private Sub VBFlexGrid1_MultiSelChange()
Dim Sum As Double, i As Long
' Recommended method as it will include the mouse drag move selection. (inverted or not)
For i = 0 To VBFlexGrid1.SelectedRows - 1
Sum = Sum + VBFlexGrid1.TextMatrix(VBFlexGrid1.SelectedRow(i), 1)
Next i
' Alternative approach but without temporary mouse drag move selection.
'For i = .FixedRows To VBFlexGrid1.Rows - 1
' If VBFlexGrid1.RowSelected(i) = True Then
' Sum = Sum + VBFlexGrid1.TextMatrix(i, 1)
' End If
'Next i
Label1.Caption = Sum
End Sub
The OCX was also updated and jumped to typelib version 1.1
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
It's suppossed to work when allowMultiSelection is True.
Otherwise use GetSelRange.
OK, thanks for reply
When I was designing the grid, I found that the fixedrow is selected by default and highlighted, vbflexgrid.selectedrows will include the fixedrow, and vbflexgrid.selectedrow(0)=0. I don't think the fixedrow should be included in selectedrows. I don't know if any attribute setting is incorrect.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by bincong
OK, thanks for reply
When I was designing the grid, I found that the fixedrow is selected by default and highlighted, vbflexgrid.selectedrows will include the fixedrow, and vbflexgrid.selectedrow(0)=0. I don't think the fixedrow should be included in selectedrows. I don't know if any attribute setting is incorrect.
I don't understand. When you select a fixed row for whatever reason then why SelectedRows should not return it ?
And you can select a fixed row only via code or when .Rows = .FixedRows, means no scrollable rows available anymore.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
I don't understand. When you select a fixed row for whatever reason then why SelectedRows should not return it ?
And you can select a fixed row only via code or when .Rows = .FixedRows, means no scrollable rows available anymore.
I usually set VBFlexGrid.Rows = 1 when initializing the grid, and use AddItem or VBFlexGrid.Rows = VBFlexGrid.Rows + 1 when loading data. However, I hope that no rows are selected when data loading is complete because I want users to manually select rows to trigger other events. How can we achieve such an effect?
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by bincong
I usually set VBFlexGrid.Rows = 1 when initializing the grid, and use AddItem or VBFlexGrid.Rows = VBFlexGrid.Rows + 1 when loading data. However, I hope that no rows are selected when data loading is complete because I want users to manually select rows to trigger other events. How can we achieve such an effect?
Well, at which point you use .SelectedRows/.SelectedRow ?
I can imagine that this might be an issue when handling the MultiSelChange event, do you ? If yes, you can have an "GridLoaded" boolean at the Form where you handle when that is only True. And while you re-arrange the data you set this boolean to False and once everything is loaded you set it to True.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
Well, at which point you use .SelectedRows/.SelectedRow ?
I can imagine that this might be an issue when handling the MultiSelChange event, do you ? If yes, you can have an "GridLoaded" boolean at the Form where you handle when that is only True. And while you re-arrange the data you set this boolean to False and once everything is loaded you set it to True.
Or what else ?
Yes, I used the method you mentioned, and I must consider whether the fixed row is selected when I use .SelectedRows/.SelectedRow
Here is my code?
Code:
Dim AllowSelChange As Boolean
'Used to determine whether the data has been loaded completely
Private Sub Form_Load()
'VBFlexGrid1 serves as a listbox
With VBFlexGrid1
.Rows = 1
.Cols = 11
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = False
.AllowMultiSelection = False
End With
'The data of VBFlexGrid2 depends on the selected row of VBFlexGrid1
With VBFlexGrid2
.Rows = 1
.Cols = 6
.SelectionMode = FlexSelectionModeByRow
.AllowSelection = True
.AllowMultiSelection = True
End With
Call LoadData
End Sub
Private Sub LoadData()
AllowSelChange = False
VBFlexGrid1.Clear FlexClearMovable 'Initialize for grids
VBFlexGrid1.Rows = 1
'----------------------
'Get data from database
'Load the data array to VBFlexGrid1
'----------------------
VBFlexGrid1.SelectRange 0, 0
'I must select the fixed row, otherwise the first row will be automatically selected
AllowSelChange = True
End Sub
Private Sub VbFlexGrid1_SelChange()
If VBFlexGrid1.Row = 0 Then Exit Sub
If AllowSelChange = False Then Exit Sub
VBFlexGrid2.Clear FlexClearMovable
VBFlexGrid2.Rows = 1
'----------------------
'Het data from database according to selected row of VBFlexGrid1
'Load the data array to VBFlexGrid2
'----------------------
VBFlexGrid2.SelectRange 0, 0
End Sub
'Remove seletedrows
Private Sub MenuRemove_Click()
Dim i%
For i = VBFlexGrid2.SelectedRows - 1 To 0 Step -1
If VBFlexGrid2.SelectedRow(i) > 0 Then 'Exclude fixed rows
If VBFlexGrid2.Rows = 2 Then
'RemoveItem will report an error when there is only one non-fixed row left
'I don't know why RemoveItem doesn't allow to remove the last non-fixed row
VBFlexGrid2.Rows = 1
Else
VBFlexGrid2.RemoveItem VBFlexGrid2.SelectedRow(i)
End If
End If
Next
End Sub
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by bincong
Yes, I used the method you mentioned, and I must consider whether the fixed row is selected when I use .SelectedRows/.SelectedRow
Thank you. Update released.
I removed the "artificial limitation from MS(H)FlexGrid" that the RemoveItem method was not allowed to remove the last non-fixed row. The vsFlexGrid does actually allow it also. So, I don't consider this a compatibility break.
Regarding .SelectedRows/.SelectedRow I find it logic that the fixed rows are also returned, since they are actually selected. I checked and vsFlexGrid returns also the fixed rows for those two properties.
Alternative is that you change your layout to actually have a "blank" movable row even though there is no data. That way you don't get into the fixed selection thingy and it may look better to the end user.
Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)
Originally Posted by Krool
Thank you. Update released.
I removed the "artificial limitation from MS(H)FlexGrid" that the RemoveItem method was not allowed to remove the last non-fixed row. The vsFlexGrid does actually allow it also. So, I don't consider this a compatibility break.
Regarding .SelectedRows/.SelectedRow I find it logic that the fixed rows are also returned, since they are actually selected. I checked and vsFlexGrid returns also the fixed rows for those two properties.
Alternative is that you change your layout to actually have a "blank" movable row even though there is no data. That way you don't get into the fixed selection thingy and it may look better to the end user.
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
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.