Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Flexgrid properties

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



How Can I select multiple row is a flexgrid (CTRL CLICK)
0
Comment
Question by:PCAbraham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

670 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