Pergunta

I’m new to programming so I apologies in advanced if I ask something stupid or use the wrong terminology. I’m trying to find all the running processes (Like in Task Manager, "Applications") and list them in ListView with the icon.

I’ve been searching around and found lots of Q&A’s regarding this but I’m struggling to get it working.

Here's the part where I'm sure it's going wrong:

ImageList imageListSmall = new ImageList();
Icon ico = Icon.ExtractAssociatedIcon(theprocess.MainModule.FileName);
imageListSmall.Images.Add(ico);
lvAppProg.SmallImageList = imageListSmall;


ListViewItem itemProcess = new ListViewItem(theprocess.ProcessName);
itemProcess.SubItems.Add(theprocess.Id.ToString());
lvAppProg.Items.AddRange(new ListViewItem[] {itemProcess});

I’m trying to list each process with its ID and icon and from my understanding, all I need to do is create an “ImageList”, extract the icon location of the target “Process”, then add the small image icon to the ListView with the Process Name and ID. (I don’t know if the icon needs to be in a separate column) Any help is much appreciated!

Thanks! :)

Foi útil?

Solução

You have to assign the Imagelist to the ListViewItem and set the imageindex like:

ListViewItem itemProcess = new ListViewItem(theprocess.ProcessName);
itemProcess.SubItems.Add(theprocess.Id.ToString());
lvAppProg.Items.AddRange(new ListViewItem[] {itemProcess});
itemProcess.ImageList = imageListSmall;
itemProcess.ImageIndex = YOURIMAGEINDEX
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top