Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display/put a button inside an ObjectListView column?

I learn to use ObjectListView in C# to show my MySQL data and I try to draw/put a delete button inside column so that when I click it, it will delete the row.

I know how to draw an image or a progress bar inside a column, but the problem is I don't know how to put a button inside. When I search Google, I found that someone said have to use custom renderer to draw a button, but I don't know how.

How to put button inside the column?

like image 963
eric_dofen Avatar asked Nov 12 '22 10:11

eric_dofen


1 Answers

This answer explains how to use the CellEditStarting event to delete a row when a specific column of that row is clicked.

You only have to add a custom renderer to that solution if you want to display some kind of delete symbol.

You don't have to implement a custom renderer to display some kind of button-image for that row. You can use the ImageGetter. I improved the answer i already referenced to. It contains an example now.

Extract:

// assign an ImageList containing at least one image to SmallImageList
objectListView1.SmallImageList = imageList1;

// always display image from index 0 as default image for deleteColumn
deleteColumn.ImageGetter = delegate {
    return 0;
};
like image 61
Rev Avatar answered Nov 14 '22 23:11

Rev