S
schaf
Hi All!
I have a question about removing my selected item from the listview
control.
My listview lstView contains listviewitems which contains another
object in the tag property.
After selecting one of the listviewitems and pressing the delete item
in the context menu the following code will be executed:
//Log the start of the deletion
for (int i = lstView.SelectedItems.Count - 1; i >= 0; i--) {
ListViewItem item = lstView.SelectedItems;
CListViewObject listViewObject = item.Tag as
CListViewObject;
IPerson person = listViewObject.person;
//Event informing the main class that the corrsponding
person can be deleted.
OnItemDeleted(person);
lstView.Items.Remove(item);
}
If I do not remove the item no exception will be fired. Otherwise a
the following exception occurs:
System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values.
Parameter name: '0' is not a valid value for 'displayIndex'.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32
displayIndex)
at System.Windows.Forms.ListView.LvnBeginDrag(MouseButtons buttons,
NMLISTVIEW nmlv)
at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
I'm using .NET 1.1 and due to no supported ToolTipText on
listViewItems i programmed a tooltiptext, which appears while the
mouse move event on the ListView. Could that be the problem or is the
event a problem ?
if (e.Button == MouseButtons.Right) {
ListViewItem listViewItem = this.lstView.GetItemAt(e.X, e.Y);
if (listViewItem != null) {
listViewItem.Selected = true;
CListViewObject listViewObject = item.Tag as
CListViewObject;
if (listViewObject != null) {
if(listViewObject.IsCustomer() == false) {
cntMnuItem.Show(lstView, new Point(e.X, e.Y));
}
}
}
}
Thanks for each hint.
Regards Marcel
I have a question about removing my selected item from the listview
control.
My listview lstView contains listviewitems which contains another
object in the tag property.
After selecting one of the listviewitems and pressing the delete item
in the context menu the following code will be executed:
//Log the start of the deletion
for (int i = lstView.SelectedItems.Count - 1; i >= 0; i--) {
ListViewItem item = lstView.SelectedItems;
CListViewObject listViewObject = item.Tag as
CListViewObject;
IPerson person = listViewObject.person;
//Event informing the main class that the corrsponding
person can be deleted.
OnItemDeleted(person);
lstView.Items.Remove(item);
}
If I do not remove the item no exception will be fired. Otherwise a
the following exception occurs:
System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values.
Parameter name: '0' is not a valid value for 'displayIndex'.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32
displayIndex)
at System.Windows.Forms.ListView.LvnBeginDrag(MouseButtons buttons,
NMLISTVIEW nmlv)
at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
I'm using .NET 1.1 and due to no supported ToolTipText on
listViewItems i programmed a tooltiptext, which appears while the
mouse move event on the ListView. Could that be the problem or is the
event a problem ?
if (e.Button == MouseButtons.Right) {
ListViewItem listViewItem = this.lstView.GetItemAt(e.X, e.Y);
if (listViewItem != null) {
listViewItem.Selected = true;
CListViewObject listViewObject = item.Tag as
CListViewObject;
if (listViewObject != null) {
if(listViewObject.IsCustomer() == false) {
cntMnuItem.Show(lstView, new Point(e.X, e.Y));
}
}
}
}
Thanks for each hint.
Regards Marcel