MSFlexgrid issue using checkboxes and populating labels

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parkergirl
    New Member
    • Jan 2008
    • 4

    MSFlexgrid issue using checkboxes and populating labels

    Hi,

    I have an msflexgrid that I need to select with checkboxes (I'm currently using WingDings font). The selection of rows cannot be anymore than three rows (randomly). Then, I need to take the data from the selected rows and populate that information into labels on another form.

    Can anybody help me with this? I'm assuming I need to use arrays some how. If anybody has any experience with this, please help!

    Thanks!
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    In Click event, before you make the Column Checked, Find the Number of Checked Rows (by looping through all the Rows of FLexGrid), if the count is already 3 then dont make it Checked..

    Regards
    Veena

    Comment

    • parkergirl
      New Member
      • Jan 2008
      • 4

      #3
      Thank you for replying. I have posted my code below in hopes that you or someone can help me. With this code, the checking of rows selected works exactly how I want it to. But, my big problem is that I cannot grab the data associated with the rows selected to put onto another form. How would I do that with the code below?

      I thought using arrays would be much easier and heard that it takes up less processing time or space than collections.

      -------------------------------------------------------------------------------------------------------------
      Option Explicit

      'variable to hold selected rows
      Private m_cSelectedRows As Collection

      Private m_lForeColorSel As Long
      Private m_lBackColorSel As Long

      Const strChecked = "รพ"
      Const strUnChecked = "o"
      --------------------------------------------------------------------------------------------------------------
      Private Sub Form_Load()
      Dim lCol As Long, lRow As Long

      'initialize "selection" settings
      Set m_cSelectedRows = New Collection
      m_lBackColorSel = vbHighlight
      m_lForeColorSel = vbHighlightText

      'initialize grid
      With MSFlexGrid1
      .Redraw = False
      .Cols = 10
      .Rows = 10
      .AllowBigSelect ion = False
      .SelectionMode = flexSelectionFr ee
      .ForeColorSel = .ForeColor
      .BackColorSel = .BackColor
      .FocusRect = flexFocusLight

      'fill grid with data
      For lRow = .FixedRows To .Rows - 1
      For lCol = 1 To .Cols - 1
      .TextMatrix(lRo w, lCol) = "R" & lRow & "C" & lCol
      Next lCol
      Next lRow

      'adding checkbox layout to first column of grid
      For lRow = .FixedRows To .Rows - 1
      .Row = lRow
      .Col = 0
      .CellFontName = "Wingdings"
      .CellFontSize = 12
      .CellAlignment = flexAlignCenter Center
      .Text = strUnChecked
      Next lRow

      .Redraw = True
      End With
      End Sub
      ------------------------------------------------------------------------------------------------------------
      Private Sub MSFlexGrid1_Mou seDown(Button As Integer, Shift As Integer, x As Single, y As Single)

      With MSFlexGrid1
      If Shift <> vbCtrlMask Then
      ClearSelectedRo ws
      End If

      If m_cSelectedRows .Count >= 3 Then
      ClearSelectedRo ws
      End If
      AddSelectedRow .MouseRow
      End With
      End Sub
      -----------------------------------------------------------------------------------------------------------------
      Private Sub ClearSelectedRo ws()
      Dim lCol As Long, lRow As Long
      Dim lColSel As Long, lRowSel As Long
      Dim lFillStyle As Long

      With MSFlexGrid1
      .Redraw = False

      'store original settings
      lCol = .Col
      lRow = .Row
      lColSel = .ColSel
      lRowSel = .RowSel
      lFillStyle = .FillStyle

      'clear selection
      .FillStyle = flexFillRepeat
      .Col = 0
      .Row = .FixedRows
      .ColSel = .Cols - 1
      .RowSel = .Rows - 1
      .CellBackColor = .BackColor
      .CellForeColor = .ForeColor

      'restore settings
      .Col = lCol
      .Row = lRow
      .ColSel = lColSel
      .RowSel = lRowSel
      .FillStyle = lFillStyle

      .Redraw = True
      .Refresh
      End With

      'looping through elements of collection before clearing collection
      Dim r As Variant
      For Each r In m_cSelectedRows
      MSFlexGrid1.Tex tMatrix(r, 0) = strUnChecked
      Next r

      'clear collection
      Do While m_cSelectedRows .Count > 0
      m_cSelectedRows .Remove (1)
      Loop
      End Sub
      -------------------------------------------------------------------------------------------------------------
      Private Sub AddSelectedRow( lCurRow As Long)
      Dim sKey As String
      Dim lCol As Long, lRow As Long
      Dim lColSel As Long, lRowSel As Long
      Dim lFillStyle As Long

      'keys in a collection can't be numeric
      sKey = "row" & CStr(lCurRow)

      With MSFlexGrid1
      .Redraw = False

      'store original settings
      lCol = .Col
      lRow = .Row
      lColSel = .ColSel
      lRowSel = .RowSel
      lFillStyle = .FillStyle

      'highlight the selection
      Dim x As Integer
      .FillStyle = flexFillRepeat
      .Col = 0
      .Row = lCurRow
      .ColSel = .Cols - 1
      .RowSel = lCurRow
      ' .CellBackColor = m_lBackColorSel
      ' .CellForeColor = m_lForeColorSel
      .TextMatrix(.Ro wSel, 0) = strChecked

      .Redraw = True

      'restore the settings
      .Col = lCol
      .Row = lRow
      .ColSel = lColSel
      .RowSel = lRowSel
      .FillStyle = lFillStyle
      End With

      On Error Resume Next
      m_cSelectedRows .Add lCurRow, sKey
      End Sub

      Comment

      • parkergirl
        New Member
        • Jan 2008
        • 4

        #4
        Maybe I can do something like below but don't know if it would work. I don't know how to hold the data in the rows selected. Help, please!

        Dim rw As Variant
        For each rw In m_cSelectedRows
        If MSFlexGrid1.Tex tMatrix(rw, 0) = strChecked Then
        'hold data in rows selected some how
        End If
        Next rw

        Comment

        Working...