Results 1 to 4 of 4

Thread: select multiple cells in MSHFlexGrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    select multiple cells in MSHFlexGrid

    I have a program and need to select multible cells in a HSHFlexGrid.
    I have it working the the folloing code with some issues
    Here is what I want I want to select mulitble cells but only one cell per col I must be able to know what cells are picked later.
    The problems are is there a better way to set the cellbackcolor? Stepping thou all cells take long on some larger grids. I have the backcollor changed depending on what is in there so I can not globaly set all backcolor.
    Is there a better way to do what I am trying?
    Is there a faster way to clear the cell backcolor?

    VB Code:
    1. Dim multi As Boolean
    2. Dim TargetSelect(200) As Integer  ' max cols possible
    3.  
    4. Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    5. ' do not want row or col 0
    6. If MSHFlexGrid1.MouseCol > 0 And MSHFlexGrid1.MouseRow > 0 Then
    7.     If Button = vbLeftButton Then
    8.         Dim lngColor As Long
    9.         If Shift = vbCtrlMask Then
    10.            ' Only one want cell allowed per col
    11.            If TargetSelect(MSHFlexGrid1.Col) < 1 Then
    12.                 lngColor = MSHFlexGrid1.BackColor
    13.                 If MSHFlexGrid1.CellBackColor = MSHFlexGrid1.BackColor Then
    14.                     lngColor = MSHFlexGrid1.BackColorSel
    15.                     TargetSelect(MSHFlexGrid1.Col) = 0
    16.                 End If
    17.                 With MSHFlexGrid1
    18.                     .CellBackColor = lngColor
    19.                      ' save what cell is marked in this col
    20.                     TargetSelect(.Col) = .Row
    21.                 End With
    22.                 mulit = True
    23.             End If
    24.            
    25.         Else
    26.             If multi = True Then
    27.               lngColor = MSHFlexGrid1.BackColor      
    28.               With MSHFlexGrid1
    29.                 tmprow = .Row
    30.                 tmpcol = .Col
    31.                 ' Take too long!
    32.                 For a = 1 To .Cols - 1
    33.                     .Col = a
    34.                     TargetSelect(.Col) = 0
    35.                     For b = 1 To .Rows - 1
    36.                         .Row = b
    37.                         If .CellBackColor = .BackColorSel Then
    38.                             ' Set all cell back to normal
    39.                             .CellBackColor = lngColor
    40.                         End If
    41.                     Next b
    42.                 Next a
    43.                 .Row = tmprow
    44.                 .Col = tmpcol
    45.               End With
    46.            End If
    47.            
    48.            lngColor = MSHFlexGrid1.BackColor
    49.    
    50.            If MSHFlexGrid1.CellBackColor = MSHFlexGrid1.BackColor Then
    51.                 lngColor = MSHFlexGrid1.BackColorSel
    52.                 TargetSelect(MSHFlexGrid1.Col) = 0
    53.            End If
    54.    
    55.            With MSHFlexGrid1
    56.                 .CellBackColor = lngColor
    57.                 TargetSelect(.Col) = .Row
    58.            End With
    59.            
    60.            multi = True
    61.        
    62.         End If
    63.    
    64.     End If
    65.  
    66. End If
    67. End Sub

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: select multiple cells in MSHFlexGrid

    well i haven't tried to work out what you're trying to do, but here's how you change the backcolor of a groups of cells (without looping):
    VB Code:
    1. With MSFlexGrid1
    2.     .Redraw = False
    3.     .FillStyle = flexFillRepeat
    4.  
    5.     ' top left of the section you want to change
    6.     .Col = 1
    7.     .Row = 3
    8.  
    9.     ' bottom right of the section
    10.     .ColSel = 3
    11.     .RowSel = 5
    12.  
    13.     ' Set any cell properties
    14.     .CellBackColor = vbBlue
    15.    
    16.     .FillStyle = flexFillSingle
    17.     .Redraw = True
    18. End With
    you might be interested in looking at the MSFlexGrid selection link in my signature for an example of this in practice.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    Re: select multiple cells in MSHFlexGrid

    Thanks but that will not work. I have the background color changed on some cells for other reasons and do not want to change them. I only want to change the ones back that have been selected.
    Ron

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: select multiple cells in MSHFlexGrid

    ahh, ok.

    i think i understand your problem - though maybe not entirely.

    it's probably best to come at this from another angle. I've used a dictionary to record the position of the coloured cells - it'll be much much faster than looping through the entire grid.

    Shift+Click on a cell to turn it Red, Ctrl-Click to turn it blue. It'll only allow one cell of each colour per column.

    I'm not sure if it does what you want cos i can't quite tell what you want - but I'm sure it can be modified.

    feel free to ask if you have any questions

    Attached Files Attached Files

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