Solved

Flexgrid properties

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

732 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