Home Forums WinForms controls Xceed Grid for WinForms editing checkbox on grid

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16118 |

    I have a column of data type bool and I would like to do the following. When I uncheck a certain checkbox on the grid, some other checkboxes will be unchecked as well. To do this, I tried subscribing the cells on the grid to the ValueChangingEventHandler. However, I find that whenever I check/uncheck a checkbox on the grid, it doesn’t jump immediately to the event handler. It goes to the event handler only after I place the focus off the checkbox.

    Is there a way that I can have the effect shown once I check/uncheck the checkbox on the grid, without the need to place focus off the checkbox in order to have the effect appeared?

     Thanks.

    Imported from legacy forums. Posted by Sop (had 784 views)

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.