Button column on grid

I think this is simple but I'm struggling.


I need a grid that has 5 columns -  two columns of text, then the next three columns are clickable buttons.

I'm looking at AddButton but I think I need the entire column to be defined as a button column.

Can you give me a staring point ?
Is this shown in one of the demos that i can look at ?

Thanks


err, "Starting point" not staring point ;)


If you want a button in every row of a column, you'd have to call grid.AddButton() in a loop for all rows.

OK.  Do you which of the demos shows adding buttons to a cell ?  I'm having trouble finding one.

Thanks

Adding a button in a cell is straightforward with the grid.AddButton() method.

Example:


begin
  advstringgrid1.AddButton(1,1,30,16,'test',haLeft,vaCenter);
end;

this adds a 32x16 pixel button in Cell 1,1 with button caption 'test'

Thanks for the help with this.

I figured out how to add BMP, icons from an ImageList, to the grid, like this :

grdWorkEnter.AddImageIdx(1,ListCount+1,1,haCenter,vaCenter);

which works great.
However when my program exits, there now is a memory leak mentioning a TCellGraphic.

In my program I regularly clear and refill the grid, which may have something to do with it.

I assume I have to free these images somehow ?
Can you offer an idea on where that would be done ?

Thanks

If you just fill the grid one time with grid.AddImageIdx() the grid will free all itself when the grid is destroyed. When you refill the grid multiple times during runtime, you need to take care to remove cell graphic elements when you add new ones. You do that with grid.Clear or grid.RemoveImageIdx() per cell. Note that grid.Clear works for cells from 0,0, to ColCount -1, RowCount- 1, so if you had changed RowCount or ColCount during operations that could affect that you do not clear all cells. It's recommended to first perform Clear and then change RowCount or ColCount.

Great - Grid.clear worked !


thanks for your help.

ps Aren't you in Belgium ? You work pretty late

Thanks again

Yes & indeed still at work.