Results 1 to 15 of 15

Thread: Selecting Multiple cells in MSFLEXGRID [RESOLVED]

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882

    Selecting Multiple cells in MSFLEXGRID [RESOLVED]

    I just added a feature to our app where the user clicks a cell in an MSFlexGrid and drags along to select multiple cells.

    When they then hover over that selection, we tool-tip-text them with the total of those cells.

    Problems is the first cell gets the little "hash-mark" selection rectangle and all the other cells get the "MS BLUE" selection color.

    Is there a way to change this behavior?
    Last edited by szlamany; Sep 15th, 2004 at 12:23 PM.

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I believe you can turn the highlighting off for a flex grid. Check the options.

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    I'm actually looking to get the first cell to get the same MS BLUE selection color as all the other cells.

    It seems odd to me that it's not the same.

    I know I can change the BACKGROUND SELECTION color - but my problem is the first cell gets no color - just the "current cell" little hash-mark rectangle.

  4. #4
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I don't think you can select, say row 5 col3 and row7 col6 at the same time. Your choices are Select Column, Select Row, or FreeForm (which selects from first cell selected to last cell selected).

    The focus box can be truned off or made heavy by setting the FlexFocus property.

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    We are allowing free-form selection.

    But really wanting the user to do either a bunch of cells in one row or one column...

    But at any rate, if you CLICK in cell 1,1 and drag along to cell 1,5 you will see what I mean.

    The 1,1 cell gets the "current cell little rectangle hash mark".

    The other cells (1,2 to 1,5) get the MS BLUE background (default color for selected cells).

    When I give the tool-tip-text TOTAL when they mouse over the selection I include all five cells (1,1 to 1,5). But that first cell really doesn't look very much selected - see what I mean.

    I want that first cell to be MS BLUE background - I know about the light and heavy "current cell" options - but that isn't where I wanted to go.

  6. #6
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    szlamany, I know exactly what you are talking about. The solution
    is to first set the Row and Col properties, and then set RowSel
    and ColSel. This effectivly will set the first cell to be highlighted
    with the blue selection along with the range of rows and
    columns. Remember that the first cell can have rows above or
    below it and columns left or right of it.



    This is a freeform selection that eliminates the start cell from only
    containing the focus rectangle and not any highlighting.

    Debt paid from database forum help. Now we are even.


    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    RobDog888 - how do I do that if the user is doing the clicking and dragging to make the selection?

  8. #8
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    Let me see if I can whip something up for you.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    If you can do without the focus rectangle then that is the way to
    go. Turn it off and you get the effect you want.


    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    Gives this effect of six cells being selected only. Started selection
    at row 4 column 2 ended at row 6 column 3.


    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    Thanks RobDog888...

    What I ended up doing - in a sub called from the MOUSEUP event is:

    VB Code:
    1. With f.flxInput(y)
    2.    If .Row = .RowSel and .Col = .ColSel Then
    3.       .FocusRect = 1
    4.    Else
    5.       .FocusRect = 0
    6.    End If
    7. End With

    Basically I switch back and forth from a LIGHT focus rectable to none at all, based on the selection range.

    Looks beautiful.

    [edit] - there is probably a need to reset the FocusRect in the ROWCOLCHANGE event as well - they can walk out of a multiple selection range with the arrow keys.
    Last edited by szlamany; Sep 15th, 2004 at 12:42 PM.

  12. #12
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    No prob.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    I was boared so I wrote a procedure to duplicate what your doing
    for the summation of a selection area. Hope you dont mind.

    VB Code:
    1. Option Explicit
    2. 'Add a MSFlexGrid to a project.
    3. Private Sub Form_Load()
    4.  
    5.     Dim i As Integer
    6.     Dim ii As Integer
    7.    
    8.     With MSFlexGrid1
    9.         .Rows = 8
    10.         .Cols = 4
    11.         .FixedRows = 1
    12.         .FixedCols = 0
    13.         .ColWidth(0) = (MSFlexGrid1.Width / 4) - 27
    14.         .ColWidth(1) = (MSFlexGrid1.Width / 4) - 27
    15.         .ColWidth(2) = (MSFlexGrid1.Width / 4) - 27
    16.         .ColWidth(3) = (MSFlexGrid1.Width / 4) - 27
    17.         For i = 1 To 7
    18.             For ii = 0 To 3
    19.                 .Row = i
    20.                 .Col = ii
    21.                 .Text = i + ii
    22.             Next
    23.         Next
    24.     End With
    25.    
    26. End Sub
    27.  
    28. Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    29.     With MSFlexGrid1
    30.         If .Row = .RowSel And .Col = .ColSel Then
    31.             .FocusRect = 1
    32.         Else
    33.             .FocusRect = 0
    34.         End If
    35.     End With
    36. End Sub
    37.  
    38. Private Sub MSFlexGrid1_SelChange()
    39.    
    40.     Dim arRows() As String
    41.     Dim arTemp() As String
    42.     Dim iRows As Integer
    43.     Dim iCols As Integer
    44.     Dim dblTotal As Double
    45.     Dim dblTemp As Double
    46.    
    47.     ReDim arRows(MSFlexGrid1.Rows)
    48.     ReDim arTemp(MSFlexGrid1.Cols)
    49.    
    50.     dblTotal = 0
    51.     arRows = Split(MSFlexGrid1.Clip, vbCr)
    52.     For iRows = 0 To UBound(arRows)
    53.         arTemp = Split(arRows(iRows), vbTab)
    54.         dblTemp = 0
    55.         For iCols = 0 To UBound(arTemp)
    56.             dblTemp = dblTemp + arTemp(iCols)
    57.         Next
    58.         Erase arTemp
    59.         dblTotal = dblTotal + dblTemp
    60.     Next
    61.     Erase arTemp
    62.     Erase arRows
    63.     MSFlexGrid1.ToolTipText = "Total of selected range = " & dblTotal
    64.    
    65. End Sub
    Don't know if its how you are doing it but I like the idea so here it is.



    VB/Outlook Guru.
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    Very nice

    We use the .TEXTMATRIX array directly - but I liked seeing the CLIP logic in use - not really allowing our users to COPY/PASTE into grids yet, so we haven't played with the CLIP logic much.

    And of course, we are doing this for a Financial Accounting package - so we use CURRENCY, not double - that datatype always scares me.

    We also don't allow our users to "re-size" much of anything at this point - no column re-sizing allowed. So we use the tool-tip-text to show them the "full data" in a cell, when they hover over it (because there are times that it isn't all visible). We are working that tool-tip-text on mouse move events. So it was a no brainer to put this code into the tool-tip-logic. We only allow a single row or single column selection at this time - in order for the total to appear.

    VB Code:
    1. If .Row <> .RowSel Then
    2.             booDoColTotal = False
    3.             If .Col = .MouseCol And .Col = .ColSel Then
    4.                 If .MouseRow <= .Row Then
    5.                     If .RowSel <= .MouseRow Then
    6.                         booDoColTotal = True
    7.                     End If
    8.                 End If
    9.                 If .MouseRow >= .Row Then
    10.                     If .RowSel >= .MouseRow Then
    11.                         booDoColTotal = True
    12.                     End If
    13.                 End If
    14.             End If
    15.             If booDoColTotal Then
    16.                 For i = .Row To .RowSel
    17.                     If IsNumeric(.TextMatrix(i, .Col)) Then
    18.                         curColTotal = curColTotal + CCur(.TextMatrix(i, .Col))
    19.                     End If
    20.                 Next i
    21.                 s2 = CStr(curColTotal)
    22.                 Call ChangeDataType(s2, Dirs.inpt, s3, Dirs.outpt, DTypes.dtaMoney, s4)
    23.                 If s4 = "" Then s2 = s3
    24.                 s1 = s1 & ", Column Selection Total: " & s2
    25.             End If
    26.         End If
    27.         If .Col <> .ColSel Then
    28.             booDoRowTotal = False
    29.             If .Row = .MouseRow And .Row = .RowSel Then
    30.                 If .MouseCol <= .Col Then
    31.                     If .ColSel <= .MouseCol Then
    32.                         booDoRowTotal = True
    33.                     End If
    34.                 End If
    35.                 If .MouseCol >= .Col Then
    36.                     If .ColSel >= .MouseCol Then
    37.                         booDoRowTotal = True
    38.                     End If
    39.                 End If
    40.             End If
    41.             If booDoRowTotal Then
    42.                 For i = .Col To .ColSel
    43.                     If IsNumeric(.TextMatrix(.Row, i)) Then
    44.                         curRowTotal = curRowTotal + CCur(.TextMatrix(.Row, i))
    45.                     End If
    46.                 Next i
    47.                 s2 = CStr(curRowTotal)
    48.                 Call ChangeDataType(s2, Dirs.inpt, s3, Dirs.outpt, DTypes.dtaMoney, s4)
    49.                 If s4 = "" Then s2 = s3
    50.                 s1 = s1 & ", Row Selection Total: " & s2
    51.             End If
    52.         End If

  15. #15
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    Thanks, I like the .Clip method personally over the .TextMatrix.
    Feel free to use it in your app. I seem to always be owing you in
    the databases forum, so this should give me some credit there.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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