列表框问题selectedindex C# [英] Listbox problem selectedindex C#
问题描述
现在我有一个列表框,我需要在其中添加日期和时间的名称,程序读取列表框自动中的每个项目,如果第一项=我的电脑日期和时间显示消息等等...但我得到了当程序到达最后一个项目时出现dat错误给我那个错误当我点击开始按钮时它不会等到第一个项目=我的pc日期和时间它继续每个项目直到到达最后一个给我那个错误
注意:用户将从2个文本框添加项目,然后单击按钮,该项目将出现在列表框中,因此我需要程序读取列表框中的每个项目,如果日期和时间= pc天蚂蚁时间显示消息
错误照片:
http ://i.stack.imgur.com/77wZM.png [ ^ ]
按钮添加项目到列表框代码:
Now I have a listbox I need to add in it name of day and time and the program read each item in listbox auto and if the first item = my pc day and time show message and so on... But I got dat error when the program reach the last item give me that error And when I click on start button it doesnot wait until the first item = my pc day and time it go on the each item until reach the last give me that error
note: The User WIll add items from 2 textbox then click on button the item will appear in listbox so i need the program read each item in listbox and if the day and time = pc day ant time show message
Error photo :
http://i.stack.imgur.com/77wZM.png[^]
in button add items to listbox code:
Listbox5.items.add(textbox1.text + textbox2.text)
Listbox5.selectedindex=0
$ 1 $ b在Button1启动计时器代码:
in Button1 start timer code:
timer1.enabled=true;
$ 1 $ b
在Timer1中的代码:
in Timer1 code:
if (listbox5.text= datetime.now.tostring("ddd") +datetime.now.tolongtime())
Messagebox.show("done")
Listbox.selectedindex +=1
我尝试了什么:
我尝试了上述代码。但我得到了错误帮助?
What I have tried:
iam tried the above codes. but i got error help?
推荐答案
如果你试图访问<$> c> c>索引哪个不存在在集合
中你会得到 ArgumentOutOfRangeException [ ^ ]
验证索引
使用前:
IF you try to access anindex
which is not present in thecollection
you will get ArgumentOutOfRangeException [^]
Validate theIndex
before use:
if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
listBox1.SelectedIndex += 1;
photo error link此处 http://i.stack.imgur.com/77wZM.png [ ^ ]
photo error link Here http://i.stack.imgur.com/77wZM.png[^]
这篇关于列表框问题selectedindex C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!