10391 : Can I have a System.Windows.Forms.Button in a Grid cell?

Question

Hi,
it is possible to place a System.Windows.Forms.Button in a GridCell? It seems that there only some types (BoolCheck for Checkboxes, and ComboText for a Combobox), but I need a Button there.

I tried it with CustomCell and its Draw Event, but you can only use a Graphics Object to draw.

Content.Value = new Button() doesn’t work either.

Thanks!

Answer

In GTP.NET we currently have no Button cell ready, but to handle this and any other special cell that you might need in the future we added the CellType.CustomCell.

grid1.GridStructure.Columns.AddNew(CellType.CustomCell);

When you use this CellType you can implement some events to handle the different modes that a cell needs to handle:

 OnCustomCellDraw  Draw the content of the cell when not in edit mode 
 OnCustomCellEditStartByKey  Edit is started by key 
 OnCustomCellEditStartByMouse  Edit is started by clicking 
 OnCustomCellEndEdit  Edit is finished 
 OnCustomCellHeight 

I would suggest to only keep one button and put it in the cell when the cell enters edit mode (OnCustomCellEditStartByKey and OnCustomCellEditStartByMouse ), and when not in edit mode I would draw an image of a button (OnCustomCellDraw ), this way you will not overload windows with a button per row.

This is similair to how we do things internally with TextBox, ComboBox, DateTimePickar and checkbox.

 

Leave a Reply