Solved

Flexgrid properties

Posted on 2004-04-13
9
1,222 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 34 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 33 total points
ID: 10820639
0
 
LVL 4

Assisted Solution

by:Mitzs
Mitzs earned 33 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now