Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Flexgrid properties

Posted on 2004-04-13
9
Medium Priority
?
1,236 Views
Last Modified: 2013-12-25



How Can I select multiple row is a flexgrid (CTRL CLICK)
0
Comment
Question by:PCAbraham
  • 2
  • 2
9 Comments
 
LVL 2

Accepted Solution

by:
gimmeadrink earned 136 total points
ID: 10819664
Hi,

This link shows you how to programatically select ranges of cells in a msflexgrid.


http://support.microsoft.com/default.aspx?scid=kb;en-us;187834

Hope this helps
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 132 total points
ID: 10820639
0
 
LVL 4

Assisted Solution

by:Mitzs
Mitzs earned 132 total points
ID: 10821396
here is a little application that does exactly what you need..
start a new project and paste this code.



Option Explicit

' variable to hold our selected rows
Private m_cSelectedRows As Collection

Private m_lForeColorSel As Long ' Our forecolor for selections
Private m_lBackColorSel As Long ' Our backcolor for selections

Private Sub Form_Load()
  Dim lCol As Long, lRow As Long
 
  ' initialise our "selection" settings
  Set m_cSelectedRows = New Collection
  m_lBackColorSel = vbHighlight
  m_lForeColorSel = vbHighlightText
 
  ' initialise the grid
  With MSFlexGrid1
    .Redraw = False
    .Cols = 10
    .Rows = 10
    .AllowBigSelection = False
    .SelectionMode = flexSelectionFree
    .ForeColorSel = .ForeColor
    .BackColorSel = .BackColor
    .FocusRect = flexFocusLight
   
    ' fill the grid with some data
    For lRow = .FixedRows To .Rows - 1
      .TextMatrix(lRow, 0) = "Row: " & lRow
      For lCol = .FixedCols To .Cols - 1
        .TextMatrix(lRow, lCol) = "R" & lRow & "C" & lCol
      Next lCol
    Next lRow
    '
    .Redraw = True
  End With
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  ' going to check whether a (new) row is selected
  ' If CTRL is pressed we add the row to the selection
  ' otherwise we clear the previous selection
 
  With MSFlexGrid1
    If .MouseCol >= .FixedCols Then
      ' not clicked on a fixed column
      Exit Sub
    End If
   
    If .MouseRow < .FixedRows - 1 Then
      ' clicked on a fixed row
      Exit Sub
    End If
   
    If Shift <> vbCtrlMask Then
      ClearSelectedRows
    End If
    AddSelectedRow .MouseRow
  End With
End Sub

Private Sub ClearSelectedRows()
  Dim lCol As Long, lRow As Long
  Dim lColSel As Long, lRowSel As Long
  Dim lFillStyle As Long
 
  If m_cSelectedRows.Count = 0 Then
    ' no previous selected rows
    Exit Sub
  End If
 
  With MSFlexGrid1
    .Redraw = False
   
    ' store the original settings
    lCol = .Col
    lRow = .Row
    lColSel = .ColSel
    lRowSel = .RowSel
    lFillStyle = .FillStyle
   
    ' clear the selection
    .FillStyle = flexFillRepeat
    .Col = .FixedCols
    .Row = .FixedRows
    .ColSel = .Cols - 1
    .RowSel = .Rows - 1
    .CellBackColor = .BackColor
    .CellForeColor = .ForeColor
   
    ' restore the settings
    .Col = lCol
    .Row = lRow
    .ColSel = lColSel
    .RowSel = lRowSel
    .FillStyle = lFillStyle
   
    .Redraw = True
    .Refresh
  End With
 
  ' clear our 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 the original settings
    lCol = .Col
    lRow = .Row
    lColSel = .ColSel
    lRowSel = .RowSel
    lFillStyle = .FillStyle
   
    ' highlight the selection
    .FillStyle = flexFillRepeat
    .Col = .FixedCols
    .Row = lCurRow
    .ColSel = .Cols - 1
    .RowSel = lCurRow
    .CellBackColor = m_lBackColorSel
    .CellForeColor = m_lForeColorSel
   
    .Redraw = True
   
    ' restore the settings
    .Col = lCol
    .Row = lRow
    .ColSel = lColSel
    .RowSel = lRowSel
    .FillStyle = lFillStyle
   
  End With
 
  ' some error handling for using collections
  On Error Resume Next
  m_cSelectedRows.Add lCurRow, sKey
End Sub



hope this helps

Mitzs
0
 
LVL 2

Expert Comment

by:gimmeadrink
ID: 11086491
IMHO, all three answers seem to address the question...

Perhaps share points?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 11086921
Split points between gimmeadrink, Mitzs & DHaest
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question