5

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?

Rev
  • 5,827
  • 4
  • 27
  • 51
eric_dofen
  • 53
  • 1
  • 4

1 Answers1

1

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;
};
Community
  • 1
  • 1
Rev
  • 5,827
  • 4
  • 27
  • 51
  • thanks for your help.. now I just need to know how to make a custom renderer to draw button inside column. – eric_dofen Mar 07 '13 at 18:13
  • I haven't tried it, but there should be no need to "insert" a button in a control sense. It should be enough to draw an image inside that column that represent a button. – Rev Mar 07 '13 at 19:56
  • @eric_dofen: I improved this answer and added a complete example on how to use an image in the delete column [here](http://stackoverflow.com/a/13191759/1790864). – Rev Mar 08 '13 at 08:08