I want to create a listView with remove buttons like this in WinForms:
After some searching, it seems like ObjectListView is the way to go. After much struggling, I've got text to show up for my items, but I can't get the icons to show up. I've tried going the ImageAspectName
route and the ImageGetter
route - no success. Here's what I've got for some sample code:
My class:
public class item
{
public string Title { get; set; }
public Image RemoveButton { get; set; }
}
And the code for putting the items in the ObjectListView:
item listItem1 = new item();
listItem1.Title = "this is a test title";
listItem1.RemoveButton = Properties.Resources.Remove;
List<item> listItems = new List<item>() { listItem1 };
objectListView1.SetObjects(listItems);
olvColumn2.ImageGetter += delegate (object rowObject) { return ((item)rowObject).RemoveButton; };
My first question is: can I just use the Properties.Resources.Remove
like I've got above? What should the Build Action be for it? Just "Resource"?
EDIT:
If I try to use objectListView1.SmallImageList
then it throws an exception (IndexOutOfRangeException):
ImageList imageList = new ImageList();
imageList.Images.Add(Properties.Resources.Remove);
objectListView1.SmallImageList = imageList;
I have also tried using a different size of the same image (16x16 instead of 256x256) but to no avail.
Here is my simple test project in case anyone wants to tell me what I'm doing wrong: https://drive.google.com/uc?export=download&id=0B_-6KdFaC6WiMmMxU0JaUktUeWs