listview item check problem
-
OK, im going to try and explain this the best I can. I have a listview that shows things by category with an associated treeview for displaying specific categories. I have the ItemCheck event handler changing categories whenever an item is checked and remove it from the listview. the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?
-
OK, im going to try and explain this the best I can. I have a listview that shows things by category with an associated treeview for displaying specific categories. I have the ItemCheck event handler changing categories whenever an item is checked and remove it from the listview. the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?
based on your words
numbers1thru9 wrote:
the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?
can you show your code??
"My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates
-
based on your words
numbers1thru9 wrote:
the problem is if the item is the last item in the listview when the box is checked/unchecked the program.cs throws an argument out or range exception. does anyone know why or how to fix it?
can you show your code??
"My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates
private void lvTasks_ItemCheck(object sender, ItemCheckEventArgs e) { if (lvTasks.Items[e.Index].Checked == false && lvTasks.Items[e.Index].SubItems[6].Text == "0") { //sql.makeCompleted(user_num, lvTasks.Items[e.Index].SubItems[4].Text); taskList.Remove(lvTasks.Items[e.Index]); lvTasks.Items[e.Index].SubItems[6].Text = "1"; lvTasks.Items[e.Index].SubItems.Add(DateTime.Today.Date.ToShortDateString()); completedTasks.Add(lvTasks.Items[e.Index]); lvTasks.Items.RemoveAt(e.Index); } else if (lvTasks.Items[e.Index].Checked == true && lvTasks.Items[e.Index].SubItems[6].Text == "1") { completedTasks.Remove(lvTasks.Items[e.Index]); lvTasks.Items[e.Index].SubItems[6].Text = "0"; lvTasks.Items[e.Index].SubItems[7].Text = ""; taskList.Add(lvTasks.Items[e.Index]); lvTasks.Items.RemoveAt(e.Index); }