从列表框中选择一个项目以在另一个列表框中显示更多项目? [英] Selecting an item from a listbox to show more items in another listbox?

查看:94
本文介绍了从列表框中选择一个项目以在另一个列表框中显示更多项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我在编程时遇到了问题,我有三个清单框,其中一个叫做" lstShows ",第二个叫做" lstSeasons ",第三个叫做" lstEpisodes ",我有两个带有季节和情节的组合框,一个组合框称为" cbSeasons ",第二个组合框称为" cbEpisodes ".我想做的是,当我按下 lstshows 中的项目时,我希望能够为其分配 lstSeasons 中的项目,并且当我想要按季节单击某个项目,我希望能够在 lstepisodes

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

例如,假设一个电视节目包含10个季节,所以我添加一个电视节目并为其分配10个季节,然后第1季有20集,第2季有15集,我希望能够在每个不同的节目和季节中添加项目.我一直在寻找每一个地方,但我找不到任何东西.

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.

这是布局 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)

我真的需要帮助.

谢谢.

推荐答案

我认为您需要做的第一件事是放置一个多维数组来存储您的信息. 有关锯齿状数组的更多详细信息: https://msdn. microsoft.com/en-us/library/hkhhsz9t(v=vs.90).aspx

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

这将为您提供50个节目",每个节目有50集.现在您可以根据需要使用该程序进行更改.

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

现在,您要将项目添加到列表框中!因此,让我们用一个很棒的for循环进行遍历

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-将其添加到页面顶部(在类声明下方)

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

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

将其视为showEpisodes(Show#,Season#,Ep#)

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

2-将值添加到数组.怎么做取决于您(使用文件,数据库或只是预定值.您甚至可以将它们放在运行时.但这是另一个问题的另一件事!)

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-将此部分添加到您的季节代码中

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

这篇关于从列表框中选择一个项目以在另一个列表框中显示更多项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆