Home Forums WinForms controls Xceed Grid for WinForms checkbox event Reply To: checkbox event

User (Old forums)
Member
Post count: 23064

You need to subscribe to the CheckBox events through the ActivatingControl event of the CellEditorManager.  This is necessary because the editor is actually initialized only when the cell receives focus, and enters the edit mode.

e.g.:

//at Form_Load

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    AddHandler GridControl1.Columns( 0 ).CellEditorManager.ActivatingControl, AddressOf CheckBoxEditor_ActivatingControl
    AddHandler GridControl1.Columns( 0 ).CellEditorManager.DeactivatingControl, AddressOf CheckBoxEditor_DeactivatingControl

  End Sub

//Event handlers

  Private Sub CellEditorManager_ActivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )

    Dim editor as Xceed.Editors.WinCheckBox = CType( e.Control, Xceed.Editors.WinCheckBox )
    AddHandler checkBox.CheckedChanged, AddressOf checkBox_CheckedChanged

  End Sub

  Private Sub CellEditorManager_DeactivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
   
    Dim editor as Xceed.Editors.WinCheckBox = CType( e.Control, Xceed.Editors.WinCheckBox )
    ‘this needs to be done, if not, subscriptions will pill up every time the editor is activated
    RemoveHandler checkBox.CheckedChanged, AddressOf checkBox_CheckedChanged
 
  End Sub

  Private sub checkBox_CheckedChanged(ByVal sender As System.Object, ByVal e As EventArgs )

    System.Diagnostics.Debug.WriteLine( CType( sender, WinCheckBox ).CheckState.ToString() )
   
  End Sub

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