Results 1 to 16 of 16

Thread: MSFlexgrid multiple selection

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    34

    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.

    Name:  Booking Form.jpg
Views: 505
Size:  36.2 KB

    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

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: MSFlexgrid multiple selection

    1. Are you asking how to select multiple 'seats' (cells) in an MSFlexGrid?
    2. With a mouse?

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    34

    Re: MSFlexgrid multiple selection

    Quote Originally Posted by SamOscarBrown View Post
    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.

  4. #4
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    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).

  5. #5
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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

    Name:  joshi1.png
Views: 274
Size:  17.1 KB

    Image after MouseUP

    Name:  joshi3.png
Views: 219
Size:  16.5 KB

    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.

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    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!!!)

  7. #7
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: MSFlexgrid multiple selection

    Best make that leap soon! It will help you tremendously! Set it automatically in your IDE for every new project.

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    34

    Re: MSFlexgrid multiple selection

    Quote Originally Posted by Spooman View Post
    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

    Name:  joshi1.png
Views: 274
Size:  17.1 KB

    Image after MouseUP

    Name:  joshi3.png
Views: 219
Size:  16.5 KB

    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

  10. #10
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: MSFlexgrid multiple selection

    DJ

    Glad you found it helpful.

    BUT .. I just noticed a weakness in my algorithm ..

    Name:  joshi4.png
Views: 309
Size:  16.1 KB

    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

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: MSFlexgrid multiple selection

    Yes, Spoo....I see a VERY easy 'fix'. One if statement.

  12. #12
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: MSFlexgrid multiple selection

    Sammi

    Shhh! Don't give it away!
    And oh yeah, leap year is approaching.

    Spoo

  13. #13
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: MSFlexgrid multiple selection

    Quote Originally Posted by Spooman View Post
    Shhh! Don't give it away!
    And oh yeah, leap year is approaching.

    Spoo
    You just did! ~smile~

  14. #14
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: MSFlexgrid multiple selection

    DJ

    My guess is that you'd want my post #10 to appear as follows

    Name:  joshi5.png
Views: 309
Size:  16.2 KB

    Spoo

  15. #15

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    34

    Re: MSFlexgrid multiple selection

    Quote Originally Posted by Spooman View Post
    DJ

    Glad you found it helpful.

    BUT .. I just noticed a weakness in my algorithm ..

    Name:  joshi4.png
Views: 309
Size:  16.1 KB

    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

  16. #16
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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)
      1. OK .. accepts the selection
      2. 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
  •  



Click Here to Expand Forum to Full Width