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. a way to execute the file on list view by doubleclick

a way to execute the file on list view by doubleclick

Scheduled Pinned Locked Moved C#
helptutorialquestion
7 Posts 3 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
    Gianpaolo Barci
    wrote on last edited by
    #1

    Hello everyone!!! Me and this problem again!!! =D This is my code:

    private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
    shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
    shellExecute.Path = @"F:\Painel de Controle ETECH\Projetos ETECH\{0}\80010005.dwg";
    shellExecute.Execute();

    }

    It works BUT open only the file written in the shellExecute.Path statement I need to find a way to execute a selected file on the list view... Well I´d many ideas and none worked.. I was thinking to put the selected file on a string and then to put this string on the end of the path statement but I didn´t figure out how to do it and mainly how to put the file name on a string when I select it on the list view control! Could anyone help me?? I´m very desperate!!!! best wishes for all!!!

    L D 2 Replies Last reply
    0
    • G Gianpaolo Barci

      Hello everyone!!! Me and this problem again!!! =D This is my code:

      private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
      {
      ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
      shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
      shellExecute.Path = @"F:\Painel de Controle ETECH\Projetos ETECH\{0}\80010005.dwg";
      shellExecute.Execute();

      }

      It works BUT open only the file written in the shellExecute.Path statement I need to find a way to execute a selected file on the list view... Well I´d many ideas and none worked.. I was thinking to put the selected file on a string and then to put this string on the end of the path statement but I didn´t figure out how to do it and mainly how to put the file name on a string when I select it on the list view control! Could anyone help me?? I´m very desperate!!!! best wishes for all!!!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Gianpaolo Barci wrote:

      I was thinking to put the selected file on a string and then to put this string on the end of the path statement

      if you mean shellExecute.Path = someString; yes that would be the thing to do.

      Gianpaolo Barci wrote:

      but I didn´t figure out how to do it

      why not? That is a programming 101 concept. What is your programming background?

      led mike

      G 1 Reply Last reply
      0
      • L led mike

        Gianpaolo Barci wrote:

        I was thinking to put the selected file on a string and then to put this string on the end of the path statement

        if you mean shellExecute.Path = someString; yes that would be the thing to do.

        Gianpaolo Barci wrote:

        but I didn´t figure out how to do it

        why not? That is a programming 101 concept. What is your programming background?

        led mike

        G Offline
        G Offline
        Gianpaolo Barci
        wrote on last edited by
        #3

        shellExecute.Path = someString; and someString represents the path to the file I selected on the listView control. Yes, It means that I´m in the right way now. The problem is right here... select the file in the ListView and put it´s path and it´s name on a string... I´m a totally dummy with event oriented programming. My knowledge is structured C, Data Structures on C.. I can do an entire B-Tree using C but I can´t implement a simple event.. oh shame on me... =(

        1 Reply Last reply
        0
        • G Gianpaolo Barci

          Hello everyone!!! Me and this problem again!!! =D This is my code:

          private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
          {
          ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
          shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
          shellExecute.Path = @"F:\Painel de Controle ETECH\Projetos ETECH\{0}\80010005.dwg";
          shellExecute.Execute();

          }

          It works BUT open only the file written in the shellExecute.Path statement I need to find a way to execute a selected file on the list view... Well I´d many ideas and none worked.. I was thinking to put the selected file on a string and then to put this string on the end of the path statement but I didn´t figure out how to do it and mainly how to put the file name on a string when I select it on the list view control! Could anyone help me?? I´m very desperate!!!! best wishes for all!!!

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          How are you populating your listview with the files? Where is the file information coming from? Each ListViewItem has a Tag property that holds an object. Save your full path to the file in there. When you need it, just cast that ListViewItem's Tag to a string and you've got the file's path. Alternatively, create a custom ListViewItem that has a Path property, then you can cast the entire item to your class and access the Path property.

          public class ListViewItemWithPath : ListViewItem
          {
          public ListViewItemWithPath(string fileName, string path)
          {
          Text = fileName;
          m_Path = path;
          }
          private string m_Path;
          public string Path
          {
          get { return m_Path; }
          set { m_Path = value; }
          }
          }

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

          G 2 Replies Last reply
          0
          • D DaveyM69

            How are you populating your listview with the files? Where is the file information coming from? Each ListViewItem has a Tag property that holds an object. Save your full path to the file in there. When you need it, just cast that ListViewItem's Tag to a string and you've got the file's path. Alternatively, create a custom ListViewItem that has a Path property, then you can cast the entire item to your class and access the Path property.

            public class ListViewItemWithPath : ListViewItem
            {
            public ListViewItemWithPath(string fileName, string path)
            {
            Text = fileName;
            m_Path = path;
            }
            private string m_Path;
            public string Path
            {
            get { return m_Path; }
            set { m_Path = value; }
            }
            }

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            G Offline
            G Offline
            Gianpaolo Barci
            wrote on last edited by
            #5

            Dave I got your point!!! Working on it right now!!! Thanks

            1 Reply Last reply
            0
            • D DaveyM69

              How are you populating your listview with the files? Where is the file information coming from? Each ListViewItem has a Tag property that holds an object. Save your full path to the file in there. When you need it, just cast that ListViewItem's Tag to a string and you've got the file's path. Alternatively, create a custom ListViewItem that has a Path property, then you can cast the entire item to your class and access the Path property.

              public class ListViewItemWithPath : ListViewItem
              {
              public ListViewItemWithPath(string fileName, string path)
              {
              Text = fileName;
              m_Path = path;
              }
              private string m_Path;
              public string Path
              {
              get { return m_Path; }
              set { m_Path = value; }
              }
              }

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

              G Offline
              G Offline
              Gianpaolo Barci
              wrote on last edited by
              #6

              I did this!

              private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
              {
              string filePath = lvFiles.SelectedItems.ToString();
              ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
              shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
              shellExecute.Path = @"F:\\Painel de Controle ETECH\\Projetos ETECH" + filePath;
              shellExecute.Execute();

              }

              Am I close??

              D 1 Reply Last reply
              0
              • G Gianpaolo Barci

                I did this!

                private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
                {
                string filePath = lvFiles.SelectedItems.ToString();
                ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
                shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
                shellExecute.Path = @"F:\\Painel de Controle ETECH\\Projetos ETECH" + filePath;
                shellExecute.Execute();

                }

                Am I close??

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                Did you sort it?

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

                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