Click here to Skip to main content
16,005,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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


in Button1 start timer code:

C#
timer1.enabled=true;



in Timer1 code:

C#
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?
Posted
Updated 29-Apr-16 17:08pm
v2
Comments
Herman<T>.Instance 29-Apr-16 10:49am    
Which error?
CHill60 29-Apr-16 10:55am    
Put the text of the error into your question (use the Improve question link). The image is not available.

IF you try to access an index which is not present in the collection you will get ArgumentOutOfRangeException [^]

Validate the Index before use:

C#
if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
               listBox1.SelectedIndex += 1;
 
Share this answer
 
photo error link Here http://i.stack.imgur.com/77wZM.png[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900