Home Forums WinForms controls Xceed Grid for WinForms How do I a button to a cell… Reply To: How do I a button to a cell…

User (Old forums)
Member
Post count: 23064

You need to use the ActivatingControl event to get access to events on controls in cells in the grid when the column is not read only, or use the Click event on the cell when the Column is read only.

e.g.:

private void Form1_Load( object sender, EventArgs e )

{

    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, “” );

//if column not readonly

    gridControl1.Columns[ “column1” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler( CellEditorManager_ActivatingControl );

    gridControl1.Columns[ “column1” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler( CellEditorManager_DeactivatingControl );

//or if readonly

    gridControl1.Columns[

“column1” ].ReadOnly = true;

    gridControl1.DataRowTemplate.Cells[

“column1” ].Click += new EventHandler( Cell_Click );

}

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 WinButton;

    if( button != null )

        System.Diagnostics.

Debug.WriteLine( button.Text );

}

void Cell_Click( object sender, EventArgs e )

{

    System.Diagnostics.

Debug.WriteLine( “cell click event” );

}

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