Welcome to the Xceed Community | Help
Community Search  
More Search Options

WinCheckbox

Sort Posts: Previous Next
  •  06-23-2009, 2:05 PM Post no. 21938

    WinCheckbox

    I have a grid with a boolean column, which uses the WinCheckbox as the editor. I need to do something when it is checked on and off. I can't use the ValueChanged of the field because it only gets called when you leave the cell, I want this to happen as soon as the checked property changes on the editor.

    I just upgraded from v1.1 to v3.8 of the grid. Previously, I was adding a handler to the CellEditor's CheckStateChanged event. I've modified the code a bit, but the CheckedChanged & CheckStateChanged events are not being fired now when I click on the checkbox in the grid.

    Any help?

  •  06-24-2009, 3:33 PM Post no. 21988 in reply to 21938

    Re: WinCheckbox

    Hi,

    is the column added programmatically or by the Designer?

    Designer case:

    Hover the column name with he mouse, right-click on the column icon (black vertical bar + gray vertical bar), select Properties...  once in the properties, select the Event view.  Double-click the "Click" event.  Put the code you need in the event handler. 

    Programming case: 

    try adding something like:

    void BooleanColumn_Click(object sender, EventArgs e)
    {
      DataCell dc = sender as DataCell;
      if(dc!=null)
        System.Diagnostics.Debug.WriteLine("I should do something useful, now...");
    }
     

    and in the code initializing the gridControl1:

    gridControl1.Columns["myBooleanColumn"].Click += new EventHandler(BooleanColumn_Click);

     


    Ghislain
    Technical Support and software developer
    Xceed Software Inc.
    Knowledge Base : http://xceed.com/kb/
    Update Center : http://xceed.com/updates/
    Documentation Center : http://xceed.com/doc/
    For everything else, there is Google
  •  07-02-2009, 9:21 AM Post no. 22215 in reply to 21988

    Re: WinCheckbox

    I have a similar situation. I need to enable/disable editing of other cells in a row based on the checked value of the 1st column of the grid. The grid is being built in code. We're using the winform grid 3.8. Here's the relevant code:

    Dim chkBox As New Xceed.Editors.WinCheckBox

    Dim col1ChkBoxEditor As New Xceed.Grid.Editors.CheckBoxEditor(chkBox)

    Dim col1ChkBoxViewer As New Xceed.Grid.Viewers.CheckBoxViewer(chkBox)

    grid1.SingleClickEdit = True

    With .Cells("column1")

    .Value = False

    .CellEditorManager = diagChkBoxEditor

    .CellViewerManager = diagChkBoxViewer

    End With

    AddHandler .Cells("column1").Click, AddressOf grid_FirstColumnClicked 

     

    The problem I'm having is the click event doesn't fire every time. If the 1st column has focus, I get the click events. If it doesn't, the user has to click twice to get the event to fire (on the second click). The visible state of the box does change though (i.e. the 1st click checks the box, the second unchecks it and I get the click event). I tried adding a handler to  the .Cells("column1").ValueChanged and it never did fire. 

    What changes do I need to make to get the click to fire every time or what event should I be using?

  •  07-02-2009, 2:01 PM Post no. 22232 in reply to 22215

    Re: WinCheckbox

    Actually, my example was not quite right.  Sorry for the confusion.  The event handler must be associated to the Editor, not to the cell.

    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 CellEditorManager_ActivatingControl

        AddHandler GridControl1.Columns( 0 ).CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_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 editor.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 editor.CheckedChanged, AddressOf checkBox_CheckedChanged

     

      End Sub

     

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

     

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

       

      End Sub

     


    Ghislain
    Technical Support and software developer
    Xceed Software Inc.
    Knowledge Base : http://xceed.com/kb/
    Update Center : http://xceed.com/updates/
    Documentation Center : http://xceed.com/doc/
    For everything else, there is Google
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.