ItemActivate of directory browser
-
Hi, I have a form which should work like a custom directory browser. The form has a TreeView & ListView (like a windows explorer). I managed to browse trough the TreeView. But I also want to Activate files in the ListView. Anyone an idea how to do this?
-
Hi, I have a form which should work like a custom directory browser. The form has a TreeView & ListView (like a windows explorer). I managed to browse trough the TreeView. But I also want to Activate files in the ListView. Anyone an idea how to do this?
Hi! What do you mean by "Activate files in the ListView"? Entries in the
ListView
can be highlighted/activated by setting theSelected
property of the correspondingListViewItem
to true, but I guess you mean something different.Regards, mav -- Black holes are the places where God divided by 0...
-
Hi! What do you mean by "Activate files in the ListView"? Entries in the
ListView
can be highlighted/activated by setting theSelected
property of the correspondingListViewItem
to true, but I guess you mean something different.Regards, mav -- Black holes are the places where God divided by 0...
If i browse to a directory which has files....I want to be able to run these files with their related software by doubleclicking in listview.....e.g. an AutoCAD file: drawing.dwg (isn't that ItemActivate?)
-
If i browse to a directory which has files....I want to be able to run these files with their related software by doubleclicking in listview.....e.g. an AutoCAD file: drawing.dwg (isn't that ItemActivate?)
ItemActivate
is an event theListView
provides - it's up to you what to do once this event is fired. You can use theProcess
class to run applications and if you give a non-executable file to run (e.g.Process.Start(@"C:\Temp\mytext.txt");
), the default application for this type of document is startedRegards, mav -- Black holes are the places where God divided by 0...
-
ItemActivate
is an event theListView
provides - it's up to you what to do once this event is fired. You can use theProcess
class to run applications and if you give a non-executable file to run (e.g.Process.Start(@"C:\Temp\mytext.txt");
), the default application for this type of document is startedRegards, mav -- Black holes are the places where God divided by 0...
I my case I only have to run files with their associated applications. So the code must provide the option to run all kind of files with extensions like: *.txt, *.jpg *.dwg, *.xls etc....I think about 10 types of files....a part of my code is like you mentioned to run files:
private void ListView1_ItemActivate(object sender, System.EventArgs e) { try { string sPath = TreeView1.SelectedNode.FullPath; string sFileName = ListView1.FocusedItem.Text; Process.Start(sPath + "\\" + sFileName); } catch (Exception Exc) { MessageBox.Show(Exc.ToString()); } } private void ProjectWindow_Load(object sender, EventArgs e) { this.ListView1.ItemActivate += new System.EventHandler this.ListView1_ItemActivate); }
But this code gives an error that the sytem cannot find the file when i double click it. The code is split up in 2 parts...the path & the file. I think it can't find the fullpath of the SelectedNode....but there must be a SelectedNode otherwise i cannot see the file in the ListView?? What am i doing wrong? -
I my case I only have to run files with their associated applications. So the code must provide the option to run all kind of files with extensions like: *.txt, *.jpg *.dwg, *.xls etc....I think about 10 types of files....a part of my code is like you mentioned to run files:
private void ListView1_ItemActivate(object sender, System.EventArgs e) { try { string sPath = TreeView1.SelectedNode.FullPath; string sFileName = ListView1.FocusedItem.Text; Process.Start(sPath + "\\" + sFileName); } catch (Exception Exc) { MessageBox.Show(Exc.ToString()); } } private void ProjectWindow_Load(object sender, EventArgs e) { this.ListView1.ItemActivate += new System.EventHandler this.ListView1_ItemActivate); }
But this code gives an error that the sytem cannot find the file when i double click it. The code is split up in 2 parts...the path & the file. I think it can't find the fullpath of the SelectedNode....but there must be a SelectedNode otherwise i cannot see the file in the ListView?? What am i doing wrong?Start a debugger and try to find it out :) Put a breakpoint to your
Process.Start()
instruction and check sPath and sFileName. Oh, and are you sure you want to useListView1.FocusedItem
instead ofListView1.SelectedItems[0]
?Regards, mav -- Black holes are the places where God divided by 0...
-
Start a debugger and try to find it out :) Put a breakpoint to your
Process.Start()
instruction and check sPath and sFileName. Oh, and are you sure you want to useListView1.FocusedItem
instead ofListView1.SelectedItems[0]
?Regards, mav -- Black holes are the places where God divided by 0...
I managed to run files....I placed a MessageBox to check what the path was of the SelectedNode....It turned out not to be the Full Path but a Folder in the tree. So I added also the string of the rootpath to that Folder.... Anyway it is running files now....however only known filetypes....when a filetype is not associated to a program by windows I get an error...is it difficult to solve that? also folders are listed in the ListView.....when I double click them....an external explorer window of the selected item is opened outside my application....but the ListView should work like an explorer too....so it must browse when a folder is double clicked and it should run when a file is selected... What is the difference between: ListView1.FocusedItem and ListView1.SelectedItems[0] ? Thanx for helping me out sofar....I am a beginner in programming. -- modified at 6:33 Tuesday 30th October, 2007