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. Get info from a listview and pass to a method ?

Get info from a listview and pass to a method ?

Scheduled Pinned Locked Moved C#
question
6 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.
  • A Offline
    A Offline
    autekre
    wrote on last edited by
    #1

    Hi, I'm writing a process manager as my first real 'project,' I've got all the info into a listview (including the pid) and a kill method that works if you manually enter the pid but how would I go about extracting the pid and passing it to the method based on which row has been clicked ? TIA. -- modified at 3:59 Sunday 26th February, 2006

    D 1 Reply Last reply
    0
    • A autekre

      Hi, I'm writing a process manager as my first real 'project,' I've got all the info into a listview (including the pid) and a kill method that works if you manually enter the pid but how would I go about extracting the pid and passing it to the method based on which row has been clicked ? TIA. -- modified at 3:59 Sunday 26th February, 2006

      D Offline
      D Offline
      darkelv
      wrote on last edited by
      #2

      if(listBox1.SelectedIndex >= 0) { string a = (string)listBox1.SelectedItem; // do you stuff here to extract the pid from string a KillDaProcess(pid); } or use SelectedItems and loop thru the items if you allow user to multi-select

      A 1 Reply Last reply
      0
      • D darkelv

        if(listBox1.SelectedIndex >= 0) { string a = (string)listBox1.SelectedItem; // do you stuff here to extract the pid from string a KillDaProcess(pid); } or use SelectedItems and loop thru the items if you allow user to multi-select

        A Offline
        A Offline
        autekre
        wrote on last edited by
        #3

        Gah, I meant listview rather than box, sorry. Though I tried something like that initially, but it just kept returning "System.Windows.Form.ListView + SelectedListViewItemCollection" and nothing much to do with whats actually in the table.

        A D 2 Replies Last reply
        0
        • A autekre

          Gah, I meant listview rather than box, sorry. Though I tried something like that initially, but it just kept returning "System.Windows.Form.ListView + SelectedListViewItemCollection" and nothing much to do with whats actually in the table.

          A Offline
          A Offline
          autekre
          wrote on last edited by
          #4

          I've managed to get the name out of the first column using lstProcesses.SelectedItems[0].Text, just have to figure out how to get it out of the third column :doh:

          1 Reply Last reply
          0
          • A autekre

            Gah, I meant listview rather than box, sorry. Though I tried something like that initially, but it just kept returning "System.Windows.Form.ListView + SelectedListViewItemCollection" and nothing much to do with whats actually in the table.

            D Offline
            D Offline
            darkelv
            wrote on last edited by
            #5

            if you use listview, there is a Tag property that let you... hmm.. tag an object to an Item or SubItem. You can just tag the pid string to Item's Tag, or you can tag a class containing the pid string + other stuffs to the tag. So once you are able to get the SelectedItem, just take the object from Tag and that will be your pid. Array array = listView1.SelectedItems; if(array.Count>0) { for(int i=0; i

            A 1 Reply Last reply
            0
            • D darkelv

              if you use listview, there is a Tag property that let you... hmm.. tag an object to an Item or SubItem. You can just tag the pid string to Item's Tag, or you can tag a class containing the pid string + other stuffs to the tag. So once you are able to get the SelectedItem, just take the object from Tag and that will be your pid. Array array = listView1.SelectedItems; if(array.Count>0) { for(int i=0; i

              A Offline
              A Offline
              autekre
              wrote on last edited by
              #6

              Ah that works brilliantly, cheers man :-D

              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