Home Forums WinForms controls Xceed Grid for WinForms Grid CheckBoxEditor

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

    Can someone please tell me how can i capture the Click event or the CheckChange event of the CheckBoxEditor Template Control(WincheckBox) while the cell is in edit mode. Please offer some help.. Been tryin to accomplish this for the pass three days.

    Imported from legacy forums. Posted by dermaine (had 9772 views)

    User (Old forums)
    Member
    Post count: 23064

    CheckBoxEditor is a template that generates cloned instances. You need to first subscribe to the ActivatingControl :

    Xceed.Grid.Editors.CheckBoxEditor chkBoxEditor = new Xceed.Grid.Editors.CheckBoxEditor();

    chkBoxEditor.ActivatingControl +=new Xceed.Grid.Editors.CellEditorEventHandler(chkBoxEditor_ActivatingControl);
    chkBoxEditor.DeactivatingControl +=new Xceed.Grid.Editors.CellEditorEventHandler(chkBoxEditor_DeactivatingControl);

    You will also want to subscribe to the deactivatingControl and unsubcribe to the events there :

    private void chkBoxEditor_ActivatingControl(object sender, Xceed.Grid.Editors.CellEditorEventArgs e)
    {
    ((Xceed.Editors.WinCheckBox)e.Control).CheckedChanged +=new EventHandler(Form1_CheckedChanged);

    }

    private void chkBoxEditor_DeactivatingControl(object sender, Xceed.Grid.Editors.CellEditorEventArgs e)
    {

    ((Xceed.Editors.WinCheckBox)e.Control).CheckedChanged -=new EventHandler(Form1_CheckedChanged);

    }

    this will do what you need.

    Imported from legacy forums. Posted by Matt (had 505 views)

    User (Old forums)
    Member
    Post count: 23064

    Hm. I am doing it in VB.NET and i just cant figure it out

    I have a grid where each row has 3 checkbox controls set by default from boolean types of data, grid is unbound and created programaticaly.

    I just want to be able to do underlaying database changes when user check/uncheck the checkbox control and it seem that there isnt a way to do this. can u help out with a VB example here

    Imported from legacy forums. Posted by Ma (had 545 views)

    User (Old forums)
    Member
    Post count: 23064

    You can handle the EditLeft event on the cell, and in the event handler verify that the new value has been committed, and if so, update the database with the new value.

    e.g.:
    <i>
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    For Each cell as Cell In GridControl2.DataRowTemplate.Cells
    AddHandler cell.EditLeft, AddressOf Me.Cell_EditLeft
    Next

    End Sub

    Private Sub Cell_EditLeft(ByVal sender As Object, ByVal e As EditLeftEventArgs )

    System.Diagnostics.Debug.WriteLine( e.Commited.ToString() )

    End Sub
    </i>

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks I made it work this way, but i am not still where i intended to be.

    1. this way if a user check the checkbox and do nothing after that i cant change the database value. So i need thecheckbox checked event or checkedchanged.

    so i tried this one and in following way:

    grid1.begininit

    grid1.Columns.Add(New Column(“name1”, GetType(Boolean)))
    grid1.Columns(8).Width = 60

    ‘Then i suscribe to the editor activating and deactivating events for particular column (or i think i do that)

    AddHandler grid1.Columns(8).CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl
    AddHandler grid1.Columns(8).CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_DeactivatingControl

    then i handle the editor activation and deactivation and add new handler to handle that event

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

    Dim editor As Xceed.grid.Editors.GridCheckBox = CType(e.Control, Xceed.Grid.Editors.GridCheckBox)
    AddHandler editor.CheckedChanged, AddressOf editor_CheckedChanged

    End Sub

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

    Dim editor As Xceed.grid.Editors.GridCheckBox = CType(e.Control, Xceed.Grid.Editors.GridCheckBox)
    AddHandler editor.CheckedChanged, AddressOf editor_CheckedChanged

    End Sub

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

    MsgBox(“checked”)

    End Sub

    But nothing happens, i figure i havent attached the handlers for the events properly, but i wonder how to achieve that for lets say particular column or for every checkbox created in grid.

    I would later on in procedure that handles checkedchanged event determine which cell and what changes to make to dbase, but i am lacking the ability to capture the checkbox changed event

    thanks in advance the last reply was good help and it took me in right direction

    Imported from legacy forums. Posted by Ma (had 515 views)

    User (Old forums)
    Member
    Post count: 23064

    I figured it out.

    The problem was atempt to suscribe to CheckboxEditor as the cell editor because this cant work.

    THIS IS THE VB WAY TO SUSCRIBE TO COLUMNS CHECKBOXES CHECKCHANGED EVENT !

    I am doing it in unbound grid

    Dim cbox As New Xceed.Grid.Editors.GridCheckBox

    ‘then when u declare columns you add this for column where you have checkboxes

    grid1.Columns(0).CellEditor = cbox

    ‘Ater columns have been declared you add handler

    AddHandler cbox.CheckedChanged, AddressOf editor_CheckedChanged

    ‘Finally handle the event as you please

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

    MsgBox(“checked”)

    End Sub

    Cheers and enjoy

    Imported from legacy forums. Posted by Ma (had 511 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok the problem i am expiriancing is: (AND I THINK IT COULD BE A BUG)

    if there is Msgbox always give me the checked message, BUT the checkbox is actually shown as checked on each second one !!! Without msgbox i dont have a problem!

    In debuger I actually get the checked value to 0 even thou i checked the box and event checked changed was actually fired inside the event checked value is 0 !!!

    can u please investigate this, as it seems there is something wrong here.

    I tried with 3,4 dffernet applications and grids and its always the same

    Without msgbox i dont have a problem, the weirdest thing is that when i wrote previose post i think everything was working fine, now i cant get rid of this silly bug.

    regards

    Mr.Confused

    Imported from legacy forums. Posted by Ma (had 665 views)

    User (Old forums)
    Member
    Post count: 23064

    The problem is that you are not using the right editor. When using the CellEditorManager class, the underlying editor for a boolean column is the WinCheckBox editor, not a GridCheckBox editor. So in your ActivatingControl event handle, you need to make this change, and the CheckedChanged event should fire properly. Moreover, in the DeactivatingControl event handle, you must use RemoveHandler and not AddHandler.

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

    Dim editor As Xceed.grid.Editors.GridCheckBox = CType(e.Control, Xceed.Grid.Editors.WinCheckBox)
    AddHandler editor.CheckedChanged, AddressOf editor_CheckedChanged

    End Sub

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

    Dim editor As Xceed.grid.Editors.GridCheckBox = CType(e.Control, Xceed.Grid.Editors.WinCheckBox)
    RemoveHandler editor.CheckedChanged, AddressOf editor_CheckedChanged

    End Sub

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

    MsgBox(“checked”)

    End Sub

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

    User (Old forums)
    Member
    Post count: 23064

    This doesnt help at all. It just dont work.

    I get the event but its on every 2nd click!

    Like many other things with this grid that dont work or work bad.

    Thanks for nothing

    Imported from legacy forums. Posted by Ma (had 791 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, you’re welcome for nothing 🙂

    It seems to work fine for many other users. May be you’re in a particular setup which makes this problem come up. The best would be for you to send <a href=”mailto:support@xceedsoft.com”>us</a> a sample application reproducing the issue, so we can figure out what is going on exactly, and get you going.

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

    User (Old forums)
    Member
    Post count: 23064

    Perfect solution. works great!.

    Imported from legacy forums. Posted by Peter (had 866 views)

    User (Old forums)
    Member
    Post count: 23064

    Although now I’m having a related problem.
    I have a data bound grid. I’m doing the following;

    private void gridEquipment_AddingDataRow(object sender, Xceed.Grid.AddingDataRowEventArgs e)
    {

    ((Xceed.Grid.Editors.CheckBoxEditor)e.DataRow.Cells[“Returned”].CellEditorManager).ActivatingControl += new Xceed.Grid.Editors.CellEditorEventHandler(cb_ActivatingControl);
    ((Xceed.Grid.Editors.CheckBoxEditor)e.DataRow.Cells[“Returned”].CellEditorManager).DeactivatingControl += new Xceed.Grid.Editors.CellEditorEventHandler(cb_DeactivatingControl);

    }

    void cb_DeactivatingControl(object sender, Xceed.Grid.Editors.CellEditorEventArgs e)
    {
    ((Xceed.Editors.WinCheckBox)e.Control).CheckedChanged -= new EventHandler(returned_CheckedChanged);
    }

    void cb_ActivatingControl(object sender, Xceed.Grid.Editors.CellEditorEventArgs e)
    {
    ((Xceed.Editors.WinCheckBox)e.Control).CheckedChanged += new EventHandler(returned_CheckedChanged);
    }

    Which works great. Though the problem I’m having now is that when I change the bound data. Which is a custom row which inherits System.Data.DataRow the grid won’t automatically update. I’m having to manually change the check box like so;

    ((Xceed.Editors.WinCheckBox)(dr.Cells[“Returned”].CellEditorControl)).Checked = true;

    Any ideas? The above is suitable as a work around, but I’d prefer not to do it.

    Cheers.

    Peter Henry.

    Imported from legacy forums. Posted by Peter (had 612 views)

    Xceed Support
    Member
    Post count: 5658

    This is a normal behavior. Because the initial state of the WinCheckBox is “Indeterminate”. So, unless you assign the Checked property, it will stay in this state.

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

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