Results 1 to 15 of 15

Thread: Multiple listboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Multiple listboxes

    Hi all.
    I have a question regarding multiple list boxes. I am coding for Visual Basic 6.

    I am developing a box office program and it is nearly complete. However, I have four listboxes, one for show name, one for time, one for date and one for day. The listboxes sit side by side.

    The show listbox is lst_show
    The date listbox is lst_date
    The day listbox is lst_day
    The time listbox is lst_time

    At the moment all the code to select the show is called by clicking the name in the show listbox. I have coded the others to follow the selection (all in a mouse down event).

    Code in lst_show:-

    Lst_date.listindex = lst_show.listindex
    Lst_time.listindex = lst_show.listindex
    Lst_day.listindex = lst_show.listindex

    And the same for selecting the shows from the other listboxes. Time, day and date.

    Code in lst_day:-

    Lst_show.listindex = lst_show.listindex
    Lst_time.listindex = lst_show.listindex
    Lst_date.listindex = lst_show.listindex

    Code in lst_date:-

    Lst_show.listindex = lst_show.listindex
    Lst_time.listindex = lst_show.listindex
    Lst_day.listindex = lst_show.listindex

    Code in lst_time:-

    Lst_show.listindex = lst_show.listindex
    Lst_day.listindex = lst_show.listindex
    Lst_date.listindex = lst_show.listindex

    All is good and the listboxes all follow each other. The problem I have is that I cannot get the event in lst_day, lst_date and lst_time to trigger the code in lst_show, the idea being that you can click the day, time, date or show to select it.

    Any ideas?

    Thank you.

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Re: Multiple listboxes

    Sorry. The code was wrong and I cannot edit the post. this is the correct code:-

    Hi all.
    I have a question regarding multiple list boxes. I am coding for Visual Basic 6.

    I am developing a box office program and it is nearly complete. However, I have four listboxes, one for show name, one for time, one for date and one for day. The listboxes sit side by side.

    The show listbox is lst_show
    The date listbox is lst_date
    The day listbox is lst_day
    The time listbox is lst_time

    At the moment all the code to select the show is called by clicking the name in the show listbox. I have coded the others to follow the selection (all in a mouse down event).

    Code in lst_show:-

    Lst_date.listindex = lst_show.listindex
    Lst_time.listindex = lst_show.listindex
    Lst_day.listindex = lst_show.listindex

    And the same for selecting the shows from the other listboxes. Time, day and date.

    Code in lst_day:-

    Lst_show.listindex = lst_day.listindex
    Lst_time.listindex = lst_day.listindex
    Lst_date.listindex = lst_day.listindex

    Code in lst_date:-

    Lst_show.listindex = lst_date.listindex
    Lst_time.listindex = lst_date.listindex
    Lst_day.listindex = lst_date.listindex

    Code in lst_time:-

    Lst_show.listindex = lst_time.listindex
    Lst_day.listindex = lst_time.listindex
    Lst_date.listindex = lst_time.listindex

    All is good and the listboxes all follow each other.


    The problem I have is that I cannot get the event in lst_day, lst_date and lst_time to trigger the code in lst_show, the idea being that you can click the day, time, date or show to select it.

    Any ideas?

    Thank you.

  3. #3
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Multiple listboxes

    Hello, welcome to the forum.

    That seems like you would need another control, like a grid instead of four listboxes.
    Because if 4 data need to be synchronized, it is like they should be displayed in the same line I think.

    Anyway, to synchronize the four listboxes:

    Code:
    Private Sub Lst_date_Click()
        Lst_time.ListIndex = Lst_date.ListIndex
        Lst_day.ListIndex = Lst_date.ListIndex
        Lst_show.ListIndex = Lst_date.ListIndex
    End Sub
    
    Private Sub Lst_day_Click()
        Lst_date.ListIndex = Lst_day.ListIndex
    End Sub
    
    Private Sub Lst_show_Click()
        Lst_date.ListIndex = Lst_show.ListIndex
    End Sub
    
    Private Sub Lst_time_Click()
        Lst_date.ListIndex = Lst_time.ListIndex
    End Sub
    Lst_date sets the other three. And the other three only need to set Lst_date.

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

    Re: Multiple listboxes

    That seems like you would need another control, like a grid instead of four listboxes.
    My thoughts exactly as I read the OP. Do you know how to use a Flexgrid? (MS- or MSH-)?
    Sam I am (as well as Confused at times).

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Multiple listboxes

    Or a ListView. The way he describes it, I'd tend to grab the ListView.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Re: Multiple listboxes

    I have to use the four listboxes.

    The text from these is used to print the info on the tickets.

    As I said, the listboxes follow eachother fine. However, the lst_show listbox is the one that fires of loads of code and opens and reads multiple files from the HDD. I just cannot get the other listboxes to trigger the lst_shows click event (just like clicking on that listbox form any of the others).

    Thank you so far.

    Dan.

  7. #7
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Multiple listboxes

    Quote Originally Posted by dmxdan View Post
    I just cannot get the other listboxes to trigger the lst_shows click event (just like clicking on that listbox form any of the others).
    The code that works is posted on post #3.

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Re: Multiple listboxes

    Hi again.

    indeed it it is.

    This still does not run the code in the lst_shows listbox, it only selects the and highlights the lsit at that index

    it needs to run the code as in a command button using the cmd_?.value = true. (I need to simulate a click on the lst_show item)

    Thanks again.

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Multiple listboxes

    In the code you posted, there is no event that runs anything.

    Anyway, the code should be in the Private Sub Lst_show_Click()

  10. #10

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Re: Multiple listboxes

    Yes, you are correct.

    All the code is in the lst_show (click) I need the same events to run from any of the listboxes clicked on that index, without placing the same code in every listbox. IE: click the lst_show box in code rather than on it.

    Thanks again.

  11. #11
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Multiple listboxes

    Quote Originally Posted by dmxdan View Post
    All the code is in the lst_show (click)
    If you have done that, it would work.
    You didn't post the actual code.

  12. #12

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Re: Multiple listboxes

    I posted the code for each of the listboxes in the first post. The code in the show listbox is around 200 lines. all the code and the system is working fine, but you can only run the code by clicking on the show listbox ONLY. I want to trigger the code in the show listbox from any of the others.

    All the listboxes are responding to the click event to select the other listboxes at the correct index all at the same time (that bit works). I need to trigger the code in the show listbox from any of the others as if they are one listbox.

  13. #13
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Multiple listboxes

    Code:
    Private Sub List1_Click()
    
      DoTheThing (List1.ListIndex)
      
    End Sub
    
    Private Sub List2_Click()
    
      DoTheThing (List2.ListIndex)
      
    End Sub
    
    Private Sub List3_Click()
    
      DoTheThing (List3.ListIndex)
      
    End Sub
    
    Private Sub List4_Click()
    
      DoTheThing (List4.ListIndex)
      
    End Sub
    
    Private Sub DoTheThing(ByVal i As Integer)
      'Do the 200 lines of code here
    End Sub

  14. #14
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Multiple listboxes

    Sometimes it is better to test something with an example.
    Attached Files Attached Files

  15. #15

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    7

    Re: Multiple listboxes

    Attachment 184790

    Here is a shot of the main screen.

    I did have to do it with a call to the code from each of the listboxes and link them together with the "listsbox.listindex = listbox.listindex on the mousedown event.

    Thank you all.

    Regards.

    Daniel.

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