Instead of adding the ProcessName to the checkeditemlist add a class like this
public class CustomCheckedItem<t>
{
public CustomCheckedItem(string Name, T Value)
{
this.Name = Name;
this.Value = Value;
}
public string Name {get;set;}
public string Value {get;set;}
public override ToString()
{
return Name;
}
}
You can add the process like this
checkedListBox1.Items.Add(new CustomCheckedItem<Process>(theprocess.ProcessName,theprocess);
Then I would make a read only property in the form that returns the checked items as an IEnumerable. You can then run a foreach on the return IEnumerable.
Something like this
private IEnumerable<process> CheckedItems
{
get
{
return checkedListBox1.CheckedItems.Cast<CustomCheckedCtem<Process>>()
.Select(r=>r.Value);
}
}
This would show the process name in the list but have the actuall process object in the background that you could access from the IEnumerable.
Bit of a workaround but should work (so long as you fix the bugs I haven't tried the code)