-
Nov 10th, 2017, 05:27 AM
#1
Thread Starter
Member
MSFlexgrid multiple selection
I am working on a cinema hall booking project. In the booking form I need to book tickets for the entire selection. Please see attached image for better clarification.
I require to book one ticket for one seat.
Please help. I have tried various options according to my experience & from other people's posts.
Thanks,
Dharmesh Joshi
-
Nov 10th, 2017, 06:37 AM
#2
Re: MSFlexgrid multiple selection
1. Are you asking how to select multiple 'seats' (cells) in an MSFlexGrid?
2. With a mouse?
-
Nov 10th, 2017, 07:56 AM
#3
Thread Starter
Member
Re: MSFlexgrid multiple selection
Originally Posted by SamOscarBrown
1. Are you asking how to select multiple 'seats' (cells) in an MSFlexGrid?
2. With a mouse?
Yes. I have selected multiple cells, now I want to print tickets for selected cells and for that I need to find out position of selected cells e.g. A7 where A is row & 7 is column. Next A8 and so on.
Last edited by joshidharmesh101; Nov 10th, 2017 at 08:04 AM.
-
Nov 10th, 2017, 01:54 PM
#4
Fanatic Member
Re: MSFlexgrid multiple selection
How I would approach it is use a transparent shape overlay control array.
Use the shape tag property or a separate array structure where the shape index
is the index of the array, to keep track whatever (e.g. Flexgrid cell / column).
-
Nov 10th, 2017, 02:10 PM
#5
Re: MSFlexgrid multiple selection
Joshi
I'd offer that it's pretty easy .. just use MouseDown and MouseUp Events
Components
- FG1 is MSFlexgrid
- Text2 is TextBox
Code snippet
Code:
Public FGrrDN As Integer
Public FGccDN As Integer
Public FGrrUP As Integer
Public FGccUP As Integer
'................
Private Sub FG1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)
'
With FG1
FGrrDN = .RowSel
FGccDN = .ColSel
End With
End Sub
'................
Private Sub FG1_MouseUp(button As Integer, shift As Integer, x As Single, y As Single)
With FG1
FGrrUP = .RowSel
FGccUP = .ColSel
'
Text2.Text = Empty
For rr = FGrrDN To FGrrUP
For cc = FGccDN To FGccUP
txt = .TextMatrix(rr, 0) + .TextMatrix(rr, cc)
Text2.Text = Text2.Text & txt & vbCrLf
' hilite selected cells for reference purposes
.Row = rr
.Col = cc
.CellBackColor = vbCyan
Next cc
Next rr
End With
End Sub
Image before MouseUP
Image after MouseUP
I've chosen to put the results in the Textbox
Natch, you can put them into a text file or anything else you'd like to
HTH
EDIT-1
Perhaps I should emphasize use of the .RowSel and .ColSel properties.
Using them eliminates the need to deal with x-pos and y-pos
EDIT-2
For demo and reference purposes, I highlighted the selected cells in the second image.
I set .CellBackColor = vbCyan.
Spoo
Last edited by Spooman; Nov 10th, 2017 at 04:18 PM.
-
Nov 10th, 2017, 04:06 PM
#6
Re: MSFlexgrid multiple selection
Very Good spoo...just a coupla things.
This line: txt = .TextMatrix(rr, 0) + .TextMatrix(rr, cc) should read" txt = .TextMatrix(rr, 0) & .TextMatrix(rr, cc) (use + for math, & for string concatenation.
I am assuming all those variables (like txt, cc, etc) are dimmed somewhere in your sample (Of course, I KNOW you are using Option Explicit!!!)
-
Nov 10th, 2017, 04:13 PM
#7
Re: MSFlexgrid multiple selection
Sammi
You are the "stickler extraordinaire" .. that's why we love you
Yes, I sometimes revert to "+" .. but at least in the next line, I used "&"
But no, sadly, I have not made the leap to Option Explicit.
At least I declared the 4 variables need by the subs.
Spoo
-
Nov 10th, 2017, 04:32 PM
#8
Re: MSFlexgrid multiple selection
Best make that leap soon! It will help you tremendously! Set it automatically in your IDE for every new project.
-
Nov 10th, 2017, 11:45 PM
#9
Thread Starter
Member
Re: MSFlexgrid multiple selection
Originally Posted by Spooman
Joshi
I'd offer that it's pretty easy .. just use MouseDown and MouseUp Events
Components
- FG1 is MSFlexgrid
- Text2 is TextBox
Code snippet
Code:
Public FGrrDN As Integer
Public FGccDN As Integer
Public FGrrUP As Integer
Public FGccUP As Integer
'................
Private Sub FG1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)
'
With FG1
FGrrDN = .RowSel
FGccDN = .ColSel
End With
End Sub
'................
Private Sub FG1_MouseUp(button As Integer, shift As Integer, x As Single, y As Single)
With FG1
FGrrUP = .RowSel
FGccUP = .ColSel
'
Text2.Text = Empty
For rr = FGrrDN To FGrrUP
For cc = FGccDN To FGccUP
txt = .TextMatrix(rr, 0) + .TextMatrix(rr, cc)
Text2.Text = Text2.Text & txt & vbCrLf
' hilite selected cells for reference purposes
.Row = rr
.Col = cc
.CellBackColor = vbCyan
Next cc
Next rr
End With
End Sub
Image before MouseUP
Image after MouseUP
I've chosen to put the results in the Textbox
Natch, you can put them into a text file or anything else you'd like to
HTH
EDIT-1
Perhaps I should emphasize use of the .RowSel and .ColSel properties.
Using them eliminates the need to deal with x-pos and y-pos
EDIT-2
For demo and reference purposes, I highlighted the selected cells in the second image.
I set .CellBackColor = vbCyan.
Spoo
Thank you very much Spoo for the help. I have used selection of text before but I am using selection in flexgrid for the first time.
Dharmesh Joshi
-
Nov 11th, 2017, 06:43 AM
#10
Re: MSFlexgrid multiple selection
DJ
Glad you found it helpful.
BUT .. I just noticed a weakness in my algorithm ..
If any magenta cells are included, they are listed too.
I assume that they represent "non-seats", ie, an aisle, and that you would not want them to be included.
I have a "fix" in mind, but I'll let you try it first.
Holler if you need any help.
Spoo
-
Nov 11th, 2017, 06:56 AM
#11
Re: MSFlexgrid multiple selection
Yes, Spoo....I see a VERY easy 'fix'. One if statement.
-
Nov 11th, 2017, 07:06 AM
#12
Re: MSFlexgrid multiple selection
Sammi
Shhh! Don't give it away!
And oh yeah, leap year is approaching.
Spoo
-
Nov 11th, 2017, 07:12 AM
#13
Re: MSFlexgrid multiple selection
Originally Posted by Spooman
Shhh! Don't give it away!
And oh yeah, leap year is approaching.
Spoo
You just did! ~smile~
-
Nov 11th, 2017, 04:35 PM
#14
Re: MSFlexgrid multiple selection
DJ
My guess is that you'd want my post #10 to appear as follows
Spoo
-
Nov 12th, 2017, 02:10 AM
#15
Thread Starter
Member
Re: MSFlexgrid multiple selection
Originally Posted by Spooman
DJ
Glad you found it helpful.
BUT .. I just noticed a weakness in my algorithm ..
If any magenta cells are included, they are listed too.
I assume that they represent "non-seats", ie, an aisle, and that you would not want them to be included.
I have a "fix" in mind, but I'll let you try it first.
Holler if you need any help.
Spoo
Yes Spoo Magenta cells represent Pathway. So they should not be included. I have excluded them by passing
If .CellBackColor = vbMagenta then Goto R:
and R: is above Next line.
Thanks for the help.
DJ
-
Nov 12th, 2017, 05:11 AM
#16
Re: MSFlexgrid multiple selection
DJ
I knew you could do it ..
EDIT-1
BTW, this was my "fix"
Code:
Private Sub FG1_MouseUp(button As Integer, shift As Integer, x As Single, y As Single)
With FG1
FGrrUP = .RowSel
FGccUP = .ColSel
'
Text2.Text = Empty
For rr = FGrrDN To FGrrUP
For cc = FGccDN To FGccUP
If Not .TextMatrix(rr, cc) = Empty Then
txt = .TextMatrix(rr, 0) + .TextMatrix(rr, cc)
Text2.Text = Text2.Text & txt & vbCrLf
' hilite selected cells for reference purposes
.Row = rr
.Col = cc
.CellBackColor = vbCyan
End If
Next cc
Next rr
End With
End Sub
Another thing that dawned on me .. add a "confirm" step
- Dragging across multiple cells can sometimes lead to inadvertent selections
- So, you might want to make use of a MsgBox control (or something of that ilk)
- OK .. accepts the selection
- ReDo .. cancels the vbCyan highlites and allows you to re-select
Food for thought.
Spoo
Last edited by Spooman; Nov 12th, 2017 at 05:58 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|