Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ItemActivate of directory browser

ItemActivate of directory browser

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gerbenschmidt
    wrote on last edited by
    #1

    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?

    M 1 Reply Last reply
    0
    • G gerbenschmidt

      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?

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! What do you mean by "Activate files in the ListView"? Entries in the ListView can be highlighted/activated by setting the Selected property of the corresponding ListViewItem to true, but I guess you mean something different.

      Regards, mav -- Black holes are the places where God divided by 0...

      G 1 Reply Last reply
      0
      • M mav northwind

        Hi! What do you mean by "Activate files in the ListView"? Entries in the ListView can be highlighted/activated by setting the Selected property of the corresponding ListViewItem to true, but I guess you mean something different.

        Regards, mav -- Black holes are the places where God divided by 0...

        G Offline
        G Offline
        gerbenschmidt
        wrote on last edited by
        #3

        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?)

        M 1 Reply Last reply
        0
        • G gerbenschmidt

          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?)

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          ItemActivate is an event the ListView provides - it's up to you what to do once this event is fired. You can use the Process 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 started

          Regards, mav -- Black holes are the places where God divided by 0...

          G 1 Reply Last reply
          0
          • M mav northwind

            ItemActivate is an event the ListView provides - it's up to you what to do once this event is fired. You can use the Process 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 started

            Regards, mav -- Black holes are the places where God divided by 0...

            G Offline
            G Offline
            gerbenschmidt
            wrote on last edited by
            #5

            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?

            M 1 Reply Last reply
            0
            • G gerbenschmidt

              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?

              M Offline
              M Offline
              mav northwind
              wrote on last edited by
              #6

              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 use ListView1.FocusedItem instead of ListView1.SelectedItems[0] ?

              Regards, mav -- Black holes are the places where God divided by 0...

              G 1 Reply Last reply
              0
              • M mav northwind

                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 use ListView1.FocusedItem instead of ListView1.SelectedItems[0] ?

                Regards, mav -- Black holes are the places where God divided by 0...

                G Offline
                G Offline
                gerbenschmidt
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups