我无法使我的列表数组出现在我的CheckBox中 [英] I Can't Make My list Array Appear In My CheckBox

查看:56
本文介绍了我无法使我的列表数组出现在我的CheckBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我非常喜欢visual basic,正在进行课堂作业。当我尝试创建一个数组程序时,它似乎工作。没有错误或任何错误。它运行。但是,完成后我会留下一个表单和一个空复选框,而
我不知道为什么。当我跟随别人的代码,以及当我尝试创建自己的代码时,甚至会发生这种情况。我确信我只是遗漏了一些明显的东西。这是我的代码。如果有人能看到它,甚至运行它,看看他们是否在
中看到我的值,我会很感激。


公共 Class Form1



私有 Sub Books_SelectedIndexChanged(sender
As 对象
e
作为 电子ventArgs
句柄 Books.SelectedIndexChanged



Dim MyBooks(3)
作为 字符串



MyBooks(0)=
< span style ="color:#a31515; font-size:small"> " The Maze Runner"



MyBooks(1)=
< span style ="color:#a31515; font-size:small"> "饥饿游戏"



MyBooks(2)=
< span style ="color:#a31515; font-size:small"> " Divergent"



MyBooks(3)=
< span style ="color:#a31515; font-size:small"> "我们明星中的错误"



对于 i
作为 整数 =
0
MyBooks.GetUpperBound(0)



Books.Items .Add(MyBooks(0))



MessageBox 。显示(MyBooks(0 ))



下一步



结束 Sub



结束 Class


解决方案

< blockquote>

您需要显示表单的构建方式:


- 什么是具有SelectedIndex Changed事件的Books?ComboBox,ListView?



从您发布的代码中可以看出,每次选择更改时都会重新创建MyBooks数组;这样效率很低。只需将MyBooks创建为加载时间。


另外,当Books SelectedIndexChanged事件发生时,你正在添加书籍,这实际上没有意义。


所以,解释你的程序应该做什么,我们会试着帮助你解决它的结构。



I am very new to visual basic and am working on a class assignment. When I try to create an array program, it seem to work. There are no errors or anything. It runs. However, after it is done I am left with a form and a empty checkbox, and I am not sure why. This even happens when I follow along with someone else's code, and when I try to create my own. I am sure I am just missing something obvious. Here is my code. I'd appreciate it if someone could look at it, or even run it and see if they see my values in the checkbox.

PublicClassForm1

PrivateSubBooks_SelectedIndexChanged(sender AsObject, e AsEventArgs) HandlesBooks.SelectedIndexChanged

DimMyBooks(3) AsString

MyBooks(0) = "The Maze Runner"

MyBooks(1) = "The Hunger Games"

MyBooks(2) = "Divergent"

MyBooks(3) = "The Fault in Our Stars"

Fori AsInteger= 0 ToMyBooks.GetUpperBound(0)

Books.Items.Add(MyBooks(0))

MessageBox.Show(MyBooks(0))

Next

EndSub

EndClass

解决方案

You need to show how your form is built up:

-what is Books which has the SelectedIndex Changed event? ComboBox, ListView?

From the code you posted it's obvious that you are recreating the MyBooks array everytime the selection changes; this is inefficient. Just create the MyBooks as Load time.

Also, you are adding to Books when Books SelectedIndexChanged event happen, that doesn't really make sense.

So, explain what your program should do and we'll try to help you with its structure.


这篇关于我无法使我的列表数组出现在我的CheckBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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