Solved

Flexgrid properties

Posted on 2004-04-13
9
1,221 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

13 Experts available now in Live!

Get 1:1 Help Now