scyphe666

scyphe666

  • NA
  • 48
  • 0

Changing folder in C# causing headache

May 16 2004 5:40 AM
I'm having trouble getting the code for changing folder when doubleclicked on in a listbox. I can go upwards in the hierarchy, but going down (entering folders instead of leaving them) creates errors etc. I've loaded the filelist into one array, folderlist into another array, then add them to an arraylist which is set as datasource to the listbox. The first item in the arraylist is a ".." to leave the current folder, and that part works just as it should, setting the correct current_folder everytime as well as checking I'm not trying to go higher than the root. This is the code that I can't get right: private void lstFiles_DoubleClick(object sender, System.EventArgs e) { m_FileIndex = lstFiles.SelectedIndex; // set index to a variable try { if(m_FileIndex > 0 && m_FileIndex <= m_TotalFolders) { m_FolderList = m_FileRoamer.GetFolders(m_Current); m_Current = Convert.ToString(m_FolderList[lstFiles.SelectedIndex-1]); m_ListBox.Clear(); lstFiles.DataSource = null; ListFiles(m_Current); } } .... as you see, I use the listboxindex-1 to select the foldername in the folderlist because index0 in the lstFiles-listbox is the ".." last in my listmethod (doing the actual listing and whatnot) where I add the arrays to the list: m_ListBox.Add(m_Parent); <-- adds ".." as the first object in the arraylist if(m_FolderList!=null) { m_ListBox.AddRange(m_FolderList); <-- adds the array of folders to the arraylist } if(m_FileList!=null) { m_ListBox.AddRange(m_FileList); <-- adds the array of files to the arraylist }

Answers (1)