Home Forums WinForms controls Xceed Grid for WinForms How to add a button cell? Reply To: How to add a button cell?

User (Old forums)
Member
Post count: 23064

It is because you specify the Text property as property to use to get the editor value, which in this case does not make sense since it is a button, not a TextBox or something. Just set it to “”, and it will work.

Note that the to handle events on the editor, you should to it this way :
<code>
WinButton saveBtn = new WinButton( “Save” );
saveBtn.ButtonType = new ButtonType( ButtonBackgroundImageType.SpinUp, ButtonImageType.SpinUp );

gridControl1.Columns[ “column1” ].CellEditorManager = new CellEditorManager( saveBtn, “”, true, true );
gridControl1.Columns[ “column1” ].CellViewerManager = new CellViewerManager( saveBtn, “” );
gridControl1.Columns[ “column1” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler( CellEditorManager_ActivatingControl );
gridControl1.Columns[ “column1” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler( CellEditorManager_DeactivatingControl );

void CellEditorManager_ActivatingControl( object sender, CellEditorEventArgs e )
{
( ( WinButton )e.Control ).Click += new EventHandler( Form1_Click );
}

void CellEditorManager_DeactivatingControl( object sender, CellEditorEventArgs e )
{
( ( WinButton )e.Control ).Click -= new EventHandler( Form1_Click );
}

void Form1_Click( object sender, EventArgs e )
{
WinButton button = sender as Button;
}

</code>

To get the a cell value out of the current row, you need to cast it to the row type on which you are position at the time.

e.g.:
<code>
string value = ( ( Xceed.Grid.DataRow )gridControl1.CurrentRow).Cells[ “column1” ].Value.ToString();
</code>

Imported from legacy forums. Posted by André (had 3677 views)