unhandled exeption in ListView

A

Aron Henning

I have a ListView that contains the subfoldes of a local drive.
Whan i click on a subfolder the listbox should display the subfolders of
this folder instead.
the funktion is as follows:
private void FolderList_SelectedIndexChanged(object sender, System.EventArgs
e)

{

try

{

ListView.SelectedListViewItemCollection SelectedDir =
this.FolderList.SelectedItems;

foreach ( ListViewItem Dir in SelectedDir )

{

FolderList.Items.Clear();

foreach (string d in Directory.GetDirectories(Dir.Text))

{

FolderList.Items.Add(d);

}

}

}

catch

{

MessageBox.Show("Error entering directory","Error",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);

}

}

*
Now when i try to access the folder "System Volume Information" I first get
my MessageBox and then a messagebox saying that I have an unhandled
exeption.
But the funny thing is that I only get this message in the release version.
Can annyboddy tel me what I do rong?

The exeption text is as follows:

************** Exception Text **************
System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values.
Parameter name: '5' 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)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
 
V

Vijaye Raji

1. System volume information is a system folder for which you don't have
access.
2. You're clearing all items on selection change (which may not make for the
best user experience). What happens is when you click on a list view item,
one event that happens is the selection change. The other event that
happens is BeginDrag. However, by the time BeginDrag event got processed,
all the items in the listview have been deleted and that's why the BeginDrag
event throws an ArgumentException (because it's expecting the drag item to
be still there).

You might want to rethink your design.

-vJ
 
A

Aron Henning

I need the hole list to be deleted. Btw, a guy at www.codeproject.com gave
me a working solution.

"Vijaye Raji" <[email protected]> skrev i en meddelelse
| 1. System volume information is a system folder for which you don't have
| access.
| 2. You're clearing all items on selection change (which may not make for
the
| best user experience). What happens is when you click on a list view
item,
| one event that happens is the selection change. The other event that
| happens is BeginDrag. However, by the time BeginDrag event got processed,
| all the items in the listview have been deleted and that's why the
BeginDrag
| event throws an ArgumentException (because it's expecting the drag item to
| be still there).
|
| You might want to rethink your design.
|
| -vJ
|
| | >I have a ListView that contains the subfoldes of a local drive.
| > Whan i click on a subfolder the listbox should display the subfolders of
| > this folder instead.
| > the funktion is as follows:
| > private void FolderList_SelectedIndexChanged(object sender,
| > System.EventArgs
| > e)
| >
| > {
| >
| > try
| >
| > {
| >
| > ListView.SelectedListViewItemCollection SelectedDir =
| > this.FolderList.SelectedItems;
| >
| > foreach ( ListViewItem Dir in SelectedDir )
| >
| > {
| >
| > FolderList.Items.Clear();
| >
| > foreach (string d in Directory.GetDirectories(Dir.Text))
| >
| > {
| >
| > FolderList.Items.Add(d);
| >
| > }
| >
| > }
| >
| > }
| >
| > catch
| >
| > {
| >
| > MessageBox.Show("Error entering directory","Error",MessageBoxButtons.OK,
| > MessageBoxIcon.Exclamation);
| >
| > }
| >
| > }
| >
| > *
| > Now when i try to access the folder "System Volume Information" I first
| > get
| > my MessageBox and then a messagebox saying that I have an unhandled
| > exeption.
| > But the funny thing is that I only get this message in the release
| > version.
| > Can annyboddy tel me what I do rong?
| >
| > The exeption text is as follows:
| >
| > ************** Exception Text **************
| > System.ArgumentOutOfRangeException: Specified argument was out of the
| > range
| > of valid values.
| > Parameter name: '5' 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)
| > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
| > at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
| > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
| > IntPtr wparam, IntPtr lparam)
| >
| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top