c# - ArgumentOutofRangeException was unhandled,"InvalidArgument=Value of '0' is not valid for 'index'." -


i have been getting error "invalidargument=value of '0' not valid 'index'."

private void button3_click(object sender, eventargs e) {     object lst=listview1.selecteditems[0].clone();     listview1.items.removeat(listview1.selecteditems[0].index);     listview2.items.add((listviewitem)lst);     sqlcommand cmd = new sqlcommand("update visitortb set checkstat=1 passno=" + text_passno.text + "", db.connect());     if (cmd.executenonquery() >= 0)     {         messagebox.show("check out complete");     } } 

you've haven't selected items in listview.

the selecteditems property collection of listviewitem objects, , collection it's possible empty.

check count property of collection first, before trying access first element.

if (listview1.selecteditems.count == 0)     return;  // rest of code 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -