Hey james it didn't work
-
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:(
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!
-
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!
Or you can just drop the Process object into the ListViewItem.Tag property... i.e. LVITEM.lParam .NET style.
-
Or you can just drop the Process object into the ListViewItem.Tag property... i.e. LVITEM.lParam .NET style.
Doh! Obvious choice too, damn VB has me thinking that Tag is a string :( James Simplicity Rules!
-
Doh! Obvious choice too, damn VB has me thinking that Tag is a string :( James Simplicity Rules!
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
-
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
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 bedlg->DoModal();
3) I forgotdelete dlg;
Took me all of 30 seconds to realize why my code wasn't compiling :-O James Simplicity Rules! -
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 bedlg->DoModal();
3) I forgotdelete dlg;
Took me all of 30 seconds to realize why my code wasn't compiling :-O James Simplicity Rules!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:
-
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:
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!
-
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!
It's cool, When I first stepped into C#, I kept having Java flashbacks and use non-existant classes like StringBuffer and StringTokenizer. Cheers