Page 38 of 42 FirstFirst ... 2835363738394041 ... LastLast
Results 1,481 to 1,520 of 1650

Thread: VBFlexGrid Control (Replacement of the MSFlexGrid control)

  1. #1481

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by rciszek View Post
    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.

  2. #1482
    Member
    Join Date
    Apr 2021
    Posts
    54

    Smile Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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
    Attached Images Attached Images  
    Attached Files Attached Files

  3. #1483
    Addicted Member
    Join Date
    May 2022
    Posts
    144

    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) ?

  4. #1484
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by lizano diaz View Post
    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.

  5. #1485
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    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.

  6. #1486

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    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.

  7. #1487
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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?

  8. #1488

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    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?
    Code:
    .hWndComboList

  9. #1489
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    Code:
    .hWndComboList
    Thank you!

    PS: for anyone that came here searching on this topic of the drop down width (in the future), I found ready-to-use code in post #1138.

  10. #1490
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    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.

  11. #1491

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    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.
    ? Can you provide a sample?

  12. #1492
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    ? Can you provide a sample?
    Yes, sure. Thanks.
    Attached Files Attached Files

  13. #1493

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    Yes, sure. Thanks.
    Thanks, but I can't replicate.

    You are using VBFLXGRD16.OCX. You may upgrade to VBFLXGRD18.OCX

  14. #1494
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Yes, I didn't check that I was using a version so outdated. Current version is working fine.
    Thank you.

  15. #1495

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    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.
    Last edited by Krool; May 9th, 2025 at 01:23 AM.

  16. #1496
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    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?

  17. #1497

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    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 ?

    Thanks

  18. #1498
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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)

  19. #1499

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    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.

  20. #1500
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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.
    OK, the next time I will. I already finished the form I was working on.

    Thanks for the fix of the scroll.

  21. #1501
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    I am experiencing that after the user selects something in a combo cell, the grid scroll down to the bottom row.
    Sample here.

    Quote Originally Posted by Krool View Post
    Thanks, but I can't replicate.

    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.

  22. #1502
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    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.

    Samples attached. Thank you very much.
    Attached Files Attached Files

  23. #1503

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Eduardo- View Post
    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.

    Fix will follow soon. Thanks!
    Last edited by Krool; May 14th, 2025 at 06:11 AM.

  24. #1504

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    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)
    Last edited by Krool; May 14th, 2025 at 02:50 PM.

  25. #1505
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,667

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Thank you Krool.

  26. #1506

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    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
    Code:
    Object={075212A8-C1CF-444E-939D-F6046CCDBC08}#1.1#0; VBFLXGRD18.OCX
    Last edited by Krool; May 19th, 2025 at 11:17 AM. Reason: default value change 50 to 0

  27. #1507

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    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..

  28. #1508
    New Member
    Join Date
    Jan 2025
    Posts
    8

    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.

  29. #1509
    New Member
    Join Date
    Jan 2025
    Posts
    8

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    in the reply above i meant to say VBFlexGrid, not flexgrid.

  30. #1510
    Junior Member
    Join Date
    May 2025
    Posts
    23

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    could you please add the function of loading arrays, like the Vsflexgrid.loadarray? thanks.

  31. #1511
    Junior Member
    Join Date
    May 2025
    Posts
    23

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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
    Code:
    Object={075212A8-C1CF-444E-939D-F6046CCDBC08}#1.1#0; VBFLXGRD18.OCX
    the value of allowselection is true and allowmultiselection is false, why the value of vbflexgrid.selectedrows is 0 when i selected many rows?

  32. #1512

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by bincong View Post
    the value of allowselection is true and allowmultiselection is false, why the value of vbflexgrid.selectedrows is 0 when i selected many rows?
    It's suppossed to work when allowMultiSelection is True.
    Otherwise use GetSelRange.

  33. #1513
    Junior Member
    Join Date
    May 2025
    Posts
    23

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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.
    Code:
    SelectionMode = FlexSelectionModeByRow
    AllowSelection = True
    AllowMultiSelection = True

  34. #1514

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by bincong View Post
    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.
    Code:
    SelectionMode = FlexSelectionModeByRow
    AllowSelection = True
    AllowMultiSelection = True
    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.

  35. #1515
    Junior Member
    Join Date
    May 2025
    Posts
    23

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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?

  36. #1516

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by bincong View Post
    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.

    Or what else ?

  37. #1517
    Junior Member
    Join Date
    May 2025
    Posts
    23

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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

  38. #1518

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by bincong View Post
    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.
    Last edited by Krool; Jun 1st, 2025 at 09:33 AM.

  39. #1519
    Junior Member
    Join Date
    May 2025
    Posts
    23

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by Krool View Post
    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

  40. #1520

    Thread Starter
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: VBFlexGrid Control (Replacement of the MSFlexGrid control)

    Quote Originally Posted by bincong View Post
    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.

Page 38 of 42 FirstFirst ... 2835363738394041 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width