Home Forums WinForms controls Xceed Grid for WinForms Adding buttons to Grid Reply To: Adding buttons to Grid

Odi [Xceed]
Spectator
Post count: 426

Hi,

I have an answer (below) to your request – but just so you know, we are planning to release a suite of editor controls that will all work with the grid, so this type of request will be even easier to solve.

Meanwhile, here’s how to do it today. You can do something like this (with v2.1):

// This will cause the editor to be activated on the first click.
grid.SingleClickEdit = true;

// Initialize a button to serve has editor and subscribe to the click event.
Button button = new Button();
button.Click += new EventHandler( button_Click );

// Initialize the cell’s to an empty string (Only necessary if the cell is containing a Null value).
foreach( Xceed.Grid.DataRow dataRow in grid.DataRows )
dataRow.Cells[“Test1”].Value = string.Empty;

// Set the editor and viwer on the column.
grid.Columns[“Test1”].CellViewer = new ControlViewer( new Button(), “Text” );
grid.Columns[“Test1”].CellEditor = new CustomEditor( button, “Text”, true );

This will get you a button-like cell in a grid, and on the click you can do what you want.

Hope this helps.

Imported from legacy forums. Posted by Odi [Xceed] (had 3777 views)