unhandled exeption in ListView
-
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)
-
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)
Aron Henning wrote: FolderList.Items.Clear(); That will be the cause. top secret xacc-ide 0.0.1