Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Msflexigrid select multiple rows 1

Status
Not open for further replies.

PeterWallace

Programmer
Apr 28, 2003
210
0
0
AU
I have a MSFlexigrid set up

I want to be able to select more than one row at a time

Is this SHIFT + Click

AND HOW do I Capture Start Row and End Row

Thanking Ypu

Peter
 



Is there any reason to actually SELECT the rows?

Do you actually want to maybe REFERENCE a range of rows?

I'm taking a guess here...
Code:
With yourFlexGridObject
   With .Range(.Rows(a), .Rows(b))
     'do stuff with your range
   End with
End with


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip

well it is up to the user

User will be presented with grid of data that comprise Bank Reconcilliation Data

Some will Have been Presented and Cleared from Bank
THESE they will wish to HIGHLIGHT

AND MOST Often Many Rows to be highlit will be grouped together .....

BUT it is always a ONE off Situation and the User Decides which are cleared and which not

Peter

 
Hugh

Thanks have used your ideas as basis for my row grouping of
msflexigrid Data


see below

'__________________
Option Explicit

' variable to hold our selected rows

Private LGridColour As Long
Private LActiveColour As Long
Private LFLagColour As Long
Private LngWork As Long
Private LngTemp As Long

Private StrWork As String


Private IBeginRow As Integer
Private IEndRow As Integer
Private CtrlPressed As Boolean
Private Sub Form_Load()
Dim lCol As Long, lRow As Long


CtrlPressed = False
' initialise the grid
With MSFlexGrid1
.Redraw = False
.Cols = 8
.Rows = 10

' AT SOME STAGE BEFORE USE
' Set LGridColour = to Normal CellbackColor of Grid
' then make LFLagColour some other colour
' So That It Stands
' out when Row Clicked

.Row = 1
LGridColour = .CellBackColor
If LGridColour = vbRed Then
LFLagColour = vbWhite
Else
LFLagColour = vbRed
End If




.AllowBigSelection = False
.SelectionMode = flexSelectionFree

' 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 decide if it is
' Start Of Group Of Rows
' colour the line OPPOSITE To What It Is
' Or
' the End Row Of Group
' Colour All Lines
' Same Colour as Start Row Of Group
' Else
' colour the line OPPOSITE To What It Is
' Clear Begin Group


Dim IReturnToRow As Integer
Dim IReturnToCol As Integer
If CtrlPressed = False Then IBeginRow = 0
With MSFlexGrid1
IReturnToRow = .MouseRow
IReturnToCol = .MouseCol
If .MouseRow > 0 Then
If Shift = vbCtrlMask Then

If CtrlPressed = False Then
.Row = .MouseRow
.Col = 1
IBeginRow = .Row
IEndRow = .Row
CtrlPressed = True
If .CellBackColor = LFLagColour Then
LActiveColour = LGridColour
Else
LActiveColour = LFLagColour
End If


PaintTheRows

IEndRow = 0
Else
If IBeginRow > 0 Then
.Row = .MouseRow
IEndRow = .Row
PaintTheRows
CtrlPressed = False
IBeginRow = 0
IEndRow = 0
LActiveColour = LGridColour

End If
End If

Else
.Row = .MouseRow
.Col = 1
IBeginRow = .Row
IEndRow = .Row
If .CellBackColor = LFLagColour Then
LActiveColour = LGridColour
Else
LActiveColour = LFLagColour
End If
PaintTheRows
CtrlPressed = False
IBeginRow = 0
IEndRow = 0
LActiveColour = LGridColour

End If
End If
.Row = IReturnToRow
.Col = IReturnToCol
End With
End Sub

Sub PaintTheRows()
With MSFlexGrid1

.Redraw = False
.FillStyle = flexFillRepeat
.Col = 1
.Row = IBeginRow
.ColSel = .Cols - 1
.RowSel = IEndRow
.CellBackColor = LActiveColour
.FillStyle = flexFillSingle
.Redraw = True
.Refresh
End With
End Sub

 
Peter,

The nice thing about using the collection is that it allows you to return useful things like;

Print "There are " & m_cSelectedRows.count & " rows selected"

and

Dim v as variant
For each v in m_cSelectedRows
Print "Row " & v & " is selected"
Next

with very little effort. I think to do these in your example we would have to loop through all rows in the grid and check their backcolor; that is a lot of work for nothing if we have a thousand rows and only one is selected.
 
Hugh

Well ... If Real Estate Agent is getting 1000 Entries on his Bank statement every day ........ Perhaps He can Buy Faster m/c


seriously though ....
Collections are not something I know much about ( no of angels who can dance on pin head comes to mind )

Learing use of collections ... may take MUCH more time than lost by My Method .. by 420 Agents using the Programme over several years

Peter
 
I didn't know anyone was using MSFlexgrid anymore. Wasn't it superceded by MSHFlexgrid? The old control is only there to make it easier to port VB5 programs to VB6 as far as I can tell from the manual, and it doesn't support ADO.

Anyway...


The user can do multi-selection by click and drag or by click and shift-click. You'll probably have the selection mode set to "by row" for this as well.

Your program can find this range by looking at the .Row and .SelRow properties which will be set to the start and end of the range of selected rows. Note that the difference between .Row and .SelRow can be either negative or positive depending on how the user selected the rows.

If you want to simulate sparse multi-selection (Ctrl-click) you'll have to do more work yourself of course.
 
I had a requirement for something like this some time back. My solution was to add a checkbox on each row, user could then select as many as they needed.

Ah, yes. Place a checkbox in the grid, set index as 0 so it's an array. Then for each row you add to the grid add a checkbox using: Load CheckBox(i)

Might have to fiddle with placment (top, left etc) to get it right

Hope this helps,

Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top