2
Answers

How to determine whether a ListView item is a file or a folder?

Gerben

Gerben

17y
3.3k
1

Hi,

I am building a form that should become custom directory browser.
How can I determine whether a selected ListView item is a file or a folder?

private void ProjectListView_ItemActivate(object sender, System.EventArgs e)

{
      try   {
               string sProjectsPath = (global::Offshore_Supports_Menu.Properties.Settings.Default.Projects_Dir);
               
string sDir = ProjectTreeView.SelectedNode.FullPath;
               
string sItem = ProjectListView.SelectedItems[0].Text;

               //If the sItem is a file then run the File
               
Process.Start(sProjectsPath + "\\" + sDir + "\\" + sItem);

               //If the sItem is a folder then open the folder in ListView
               
               
}

      catch (Exception Exc) { MessageBox.Show(Exc.ToString()); }

}

 

 

Answers (2)