0

Alright, so i have a problem with my programming, i have three checkedlistboxes, one called "lstShows" 2nd is called "lstSeasons" and third is called "lstEpisodes" and i have two comboboxes that have seasons and episodes in them, one combobox is called "cbSeasons" and 2nd is called "cbEpisodes. so what i'm trying to do is, when i press on an item in lstshows, i want to be able to assign to it items from lstSeasons, and when i want to click on an item in seasons i want to be able to assign items to it in lstepisodes

So for example lets say, a tv shows contains 10 seasons, so i add that tv shows and assign 10 seasons for it, then season 1, has 20 episodes, and seasons 2 has 15 episodes, i want to be able to add items to each different show, and season. i have been looking every where but i could not find anything.

Here is the layout https://www.dropbox.com/s/u6xc3sb43ksq8qr/Capture.PNG?dl=0

and i tried to do the code, i done this but it does not work.

Dim item As String = lstSeasons.SelectedItem
    lstEpisodes.Items.Add(item)

I really need help with this.

Thank you.

22
  • Are you stuck trying to add ListItems from lstSeasons to cbSeasons? Jul 24, 2016 at 15:53
  • Is lstShows the .Name property or the .Caption property, If it's .Name try IstShows.AddItem [Item] otherwise ListBox1.AddItem [Item] should do it. ´ListBox1` ist of course only an example. Jul 24, 2016 at 15:57
  • that is not what i want, what i want is, so i add a new show to a list box, and then assign seasons to the selected Item from lstShow, and then lets say i have another show that i added, and then when i press on that show, i want to add different seasons to that selected item from lstshows. so like when i switch between the shows, the seasons items and episod items change aswell acordingly to that show.
    – Yousi
    Jul 24, 2016 at 16:00
  • 1
    Are you coding in vb.net or vba? Jul 24, 2016 at 18:52
  • Im coding in vba windows forms.
    – Yousi
    Jul 24, 2016 at 23:54

2 Answers 2

0

First of all, your data must be stored somewhere. For example, you can have one worksheet per show, have the seasons in column A and for each season have the episodes in the same row (starting at column B). If you don't want this data to be seen, just hide the sheets.

So if I understood correctly, first you want to select a show, then the seasons of this show appear in the 2nd listbox, and then when you select a season the episodes of this season appear in the 3rd listbox.

First, you need to add all you shows to the 1st listbox. Here, I'll assume that you have 10 shows, that their corresponding worksheets are Worksheets(1) to Worksheets(10), and that the name of the worksheet is the name of the show (but you can do as you wish, for example storing the show's name in a particular cell).

    Dim showName as String
    For i = 1 To 10
       showName = Worksheets(i).Name
       lstShows.AddItem showName
    Next i

Then, to get the seasons listbox to change when you select a particular show, you can do this :

Private Sub lstShows_Change()

Call Me.lstSeasons.Clear

showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row

Dim i As Integer

    For i = 1 To rowCount
       Me.lstSeasons.AddItem sh.Cells(i,1).Value
    Next i

End Sub

And to get the episodes listbox to change when you select a particular season, you can do this :

Private Sub lstSeasons_Change()

Call Me.lstEpisodes.Clear

showName = Me.lstShows.Value
Dim sh as Worksheet
Set sh = ThisWorkbook.Sheets(showName)
rowCount = sh.Cells(sh.Rows.Count,"A").End(xlUp).Row

Dim colCount As Integer
Dim i As Integer
Dim j As Integer

    For i = 1 To rowCount
       If Me.lstSeasons.Value = sh.Cells(i,1).Value Then
          colCount = sh.Cells(i, sh.Columns.Count).End(xlToLeft).Column
          For j = 2 To colCount
             Me.lstEpisodes.AddItem sh.Cells(i,j).Value
          Next j              
    Next i

End Sub

Hope this will help !

1
  • the code is showing all red underlines, and im using a checked listbox, the code is not working. but thanks for trying to help, if you can, please look at this image, try to replicate what i have and write up a code that works on the program that you replicated. here is my layout with the names. dropbox.com/home?preview=Capture.PNG
    – Yousi
    Jul 25, 2016 at 7:52
0

First thing I believe you need to do is to put a multi dimensional array to store your information. More details about jagged arrays: https://msdn.microsoft.com/en-us/library/hkhhsz9t(v=vs.90).aspx

so you can use it this way for example:

Dim shows(50)(50) As string

This will give you 50 "shows" with 50 episodes each. now you can change those using the program as needed.

Now into the next part which is inserting those in. You can modify them by assigning a value by

 shows(1)(12) = "ep12nameofshow1"

Where you can assign the string as a variable if you want to be able to manually change the name during runtime

Now you want to add the items to your listbox! So lets go over that with a great little for-loop

For Each episode As String In shows(1) 'show number here
    lstEpisodes.Items.Add(episode)
Next

please note that I didn't test this since I don't have access to most of your code so please inform me if there are any problems you are facing.

Update This code should be working:

1- Add this at top of your page (below class declaration)

Dim showEpisodes(99)(99)() As String

think of it as showEpisodes(Show#,Season#,Ep#)

2- Add values to your array. How you do that is up to you (use a file, database or just predetermined values. You can even put them in run time. But that's another thing for another question!)

3- Add this part to your season's code

For Each element As String In showEpisodes(lstShows.SelectedIndex)(lstSeasons.SelectedIndex)
    lstEpisodes.Items.Add(element)
Next
14
  • hi zaid, thank you for trying to help, but that code is not working for some reason, if you want i can give you the program and you can test the right code in real time, i tried and looked everywhere, but i think you are the closes to what i need. Here is the program, please try it on that: dropbox.com/s/vavoey39bbgahqk/SHOWBOX.rar?dl=0
    – Yousi
    Jul 26, 2016 at 10:46
  • I can check it for you tonight. I am a little busy right now. But I promise you to check it tonight! Jul 26, 2016 at 11:03
  • thanks alot zaid, and if you get it working you are my hero and a legend. thanks again.
    – Yousi
    Jul 26, 2016 at 11:40
  • did you find the solution for it? because i really need it. Thank you.
    – Yousi
    Jul 28, 2016 at 5:47
  • Can you please check it and try the code already, i really need it for my school project.
    – Yousi
    Jul 30, 2016 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.