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. Hey james it didn't work

Hey james it didn't work

Scheduled Pinned Locked Moved C#
help
9 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    hello james..thanks for ur help. but saddly it didn't work. the method Add() must take a string or a ListViewItem .. i hope we can get a better solution..thanks :))) shadowman:(

    J 1 Reply Last reply
    0
    • L Lost User

      hello james..thanks for ur help. but saddly it didn't work. the method Add() must take a string or a ListViewItem .. i hope we can get a better solution..thanks :))) shadowman:(

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Sorry, confused ListBox and ListView :-P I think the current technique is to derive a class from ListViewItem and use that, so...

      public class ProcessListViewItem : ListViewItem
      {
      public readonly Process Process;
      public ProcessListViewItem(Process p) : this(p.ProcessName)
      {
      Process = p;
      }
      }

      Now the Add method will work when you pass in an instance of this new list view item

      Process [] Processes = Process.GetProcesses();

      foreach( Process p in Processes )
      {
      myListView.Items.Add( new ProcessListViewItem(p) );
      }

      Then when you want to get the underlying process object you just cast the ListViewItem returned from the Items collection back to the ProcessListViewItem and access the Process property. HTH, James Simplicity Rules!

      N 1 Reply Last reply
      0
      • J James T Johnson

        Sorry, confused ListBox and ListView :-P I think the current technique is to derive a class from ListViewItem and use that, so...

        public class ProcessListViewItem : ListViewItem
        {
        public readonly Process Process;
        public ProcessListViewItem(Process p) : this(p.ProcessName)
        {
        Process = p;
        }
        }

        Now the Add method will work when you pass in an instance of this new list view item

        Process [] Processes = Process.GetProcesses();

        foreach( Process p in Processes )
        {
        myListView.Items.Add( new ProcessListViewItem(p) );
        }

        Then when you want to get the underlying process object you just cast the ListViewItem returned from the Items collection back to the ProcessListViewItem and access the Process property. HTH, James Simplicity Rules!

        N Offline
        N Offline
        Neil Van Note
        wrote on last edited by
        #3

        Or you can just drop the Process object into the ListViewItem.Tag property... i.e. LVITEM.lParam .NET style.

        J 1 Reply Last reply
        0
        • N Neil Van Note

          Or you can just drop the Process object into the ListViewItem.Tag property... i.e. LVITEM.lParam .NET style.

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          Doh! Obvious choice too, damn VB has me thinking that Tag is a string :( James Simplicity Rules!

          N 1 Reply Last reply
          0
          • J James T Johnson

            Doh! Obvious choice too, damn VB has me thinking that Tag is a string :( James Simplicity Rules!

            N Offline
            N Offline
            Neil Van Note
            wrote on last edited by
            #5

            James T. Johnson wrote: damn VB has me thinking that Tag is a string It's been a long time since I have bothered with VB, but as I remember it, it has a tendency of doing that... X| Regards

            J 1 Reply Last reply
            0
            • N Neil Van Note

              James T. Johnson wrote: damn VB has me thinking that Tag is a string It's been a long time since I have bothered with VB, but as I remember it, it has a tendency of doing that... X| Regards

              J Offline
              J Offline
              James T Johnson
              wrote on last edited by
              #6

              After working in C# for so long I wasn't paying attention one day when I started to write a quick MFC app and I wound up writing this.

              CSettingsDialog dlg = new CSettingsDialog();
              dlg.ShowDialog();
              }

              For those that haven't learned C++ yet I made 3 errors 1) dlg should be a pointer 2) it should be dlg->DoModal(); 3) I forgot delete dlg; Took me all of 30 seconds to realize why my code wasn't compiling :-O James Simplicity Rules!

              N 1 Reply Last reply
              0
              • J James T Johnson

                After working in C# for so long I wasn't paying attention one day when I started to write a quick MFC app and I wound up writing this.

                CSettingsDialog dlg = new CSettingsDialog();
                dlg.ShowDialog();
                }

                For those that haven't learned C++ yet I made 3 errors 1) dlg should be a pointer 2) it should be dlg->DoModal(); 3) I forgot delete dlg; Took me all of 30 seconds to realize why my code wasn't compiling :-O James Simplicity Rules!

                N Offline
                N Offline
                Neil Van Note
                wrote on last edited by
                #7

                No, You made 4 errors... :(( 4. If it is a simple modal dialog, You should just have decared it as a stack variable in the first place. No pointer, no delete, no worries... :cool:

                J 1 Reply Last reply
                0
                • N Neil Van Note

                  No, You made 4 errors... :(( 4. If it is a simple modal dialog, You should just have decared it as a stack variable in the first place. No pointer, no delete, no worries... :cool:

                  J Offline
                  J Offline
                  James T Johnson
                  wrote on last edited by
                  #8

                  I forget what it was for now, but there was some reason I had that. I wonder if Colin remembers the code :) James Simplicity Rules!

                  N 1 Reply Last reply
                  0
                  • J James T Johnson

                    I forget what it was for now, but there was some reason I had that. I wonder if Colin remembers the code :) James Simplicity Rules!

                    N Offline
                    N Offline
                    Neil Van Note
                    wrote on last edited by
                    #9

                    It's cool, When I first stepped into C#, I kept having Java flashbacks and use non-existant classes like StringBuffer and StringTokenizer. Cheers

                    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