Home Forums WinForms controls Xceed Grid for WinForms editing checkbox on grid Reply To: editing checkbox on grid

Xceed Support
Member
Post count: 5658

You need to use the ActivatingControl event to get the immediate value changed event. Here is a code example (the “SelectAll” column will modify the other ones):

private void Form1_Load( object sender, EventArgs e )
{
  Column col1 = new Column( “SelectAll”, typeof( bool ) );
  Column col2 = new Column( “Column1”, typeof( bool ) );
  Column col3 = new Column( “Column2”, typeof( bool ) );
  Column col4 = new Column( “Column3”, typeof( bool ) );
  Column col5 = new Column( “Column4”, typeof( bool ) );
  Column col6 = new Column( “Column5”, typeof( bool ) );
  Column col7 = new Column( “Column6”, typeof( bool ) );
  gridControl1.Columns.Add( col1 );
  gridControl1.Columns.Add( col2 );
  gridControl1.Columns.Add( col3 );
  gridControl1.Columns.Add( col4 );
  gridControl1.Columns.Add( col5 );
  gridControl1.Columns.Add( col6 );
  gridControl1.Columns.Add( col7 );

  for( int i = 0; i < 20; i++ )
  {
    Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
    foreach( Cell cell in row.Cells )
    {
      cell.Value = false;
    }
    row.EndEdit();
  }
  gridControl1.SingleClickEdit = true;
  dataRowTemplate1.Cells[ “SelectAll” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler( CellEditorManager_ActivatingControl );
  dataRowTemplate1.Cells[ “SelectAll” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler( CellEditorManager_DeactivatingControl );
}

void CellEditorManager_ActivatingControl( object sender, CellEditorEventArgs e )
{
  ( ( WinCheckBox )e.Control ).CheckedChanged += new EventHandler( Form1_CheckedChanged );
}

void CellEditorManager_DeactivatingControl( object sender, CellEditorEventArgs e )
{
  ( ( WinCheckBox )e.Control ).CheckedChanged -= new EventHandler( Form1_CheckedChanged );
}

void Form1_CheckedChanged( object sender, EventArgs e )
{
  for( int i = 1; i < gridControl1.Columns.Count; i++ )
  {
    ( ( Xceed.Grid.DataRow )gridControl1.CurrentRow ).Cells[ i ].Value = ( ( WinCheckBox )sender ).Checked;
  }
}

Imported from legacy forums. Posted by CharlesB (had 2349 views)