GridView CheckBox CellValueChanged

11 posts, 1 answers
  1. Vasilis
    Vasilis avatar
    3 posts
    Member since:
    Sep 2011

    Posted 11 Jan 2012 Link to this post

    Hello, 

    I have a problem regarding checkboxes inside gridview. 
    When I check the checkbox at the GUI seem to be checked but the value at the CellValueChanged event that raises is not checked.
    Inside the code of the event the checkbox is checked when I click anywhere else on the grid.

    My event handler code is 

      private void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
            {
                bool isChecked = (bool)radGridView1.CurrentRow.Cells[2].Value;


                if (isChecked == true)
                {
                    MessageBox.Show("Thanks you");
                }
            }


    Do you have any suggestions ? 
    PS: I send you a link with a sample project, if that helps. http://www.megaupload.com/?d=W1ACJXFS 


    Thank you in advance
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 16 Jan 2012 Link to this post

    Hi Vasilis,

    Thank you for writing.

    The observed behavior is the default behavior of RadGridView. By clicking the check box, you put the checkbox in edit mode and it will go out of this mode only when you change the row. You can make the editor submit its value when its ToggleState is changed calling the EndEdit method of RadGridView when the value of the check box editor is changed:
    void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
    {
        RadCheckBoxEditor editor = e.ActiveEditor as RadCheckBoxEditor;
        editor.ValueChanged -= new EventHandler(editor_ValueChanged);
        editor.ValueChanged += new EventHandler(editor_ValueChanged);
    }
     
    void editor_ValueChanged(object sender, EventArgs e)
    {
        radGridView1.EndEdit();
    }

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Greetings,
    Stefan
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  3. Vasilis
    Vasilis avatar
    3 posts
    Member since:
    Sep 2011

    Posted 23 Jan 2012 Link to this post

    Hello, 

    I have one more question about the checkbox. Now I have some problems with the edit modes. I am trying to put another cell in the grid in edit mode when the checkbox is checked , based on the previously used code you gave me.

    I use the following code at the value_changed event: 
    void Selection_ValueChanged(object sender, EventArgs e)
            {
                radGridView1.EndEdit();
     
                bool isChecked = (bool)radGridView1.CurrentRow.Cells[1].Value;
     
                if (isChecked == true)
                {
                    radGridView1.CurrentRow.Cells[2].BeginEdit();
     
                    radGridView1.EndEdit();
     
     
                }
            }

    The problem is that the cell[2] goes in edit more instantly and directly loses it. 
    Do you have any suggestions ? 
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 26 Jan 2012 Link to this post

    Hello Vasilis,

    I noticed that you are calling the EndEdit method twice. The second call to the EndEdit method is not necessary in your scenario. Removing it will solve the issue.

    Do not hesitate to contact me, if you need further assistance. 

    Kind regards,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  5. Vasilis
    Vasilis avatar
    3 posts
    Member since:
    Sep 2011

    Posted 26 Jan 2012 Link to this post

    Hello , 

    thanks for the reply. 
    I removed the endedit but it only works for the first row.
    When I click to another row it works in a random way. To better understand the problem I am giving you the source code.


  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 31 Jan 2012 Link to this post

    Hi Vasillis,

    Please accept our apologies for the introduced inconvenience. 

    I logged the issue in our Public Issue Tracking System. It will be addressed in one of our next releases. Currently, I can not provide you with a work-around to begin editing the next cell after checking the checkbox editor.

    Thank your for the report. Your Telerik points have been updated.

    All the best,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  7. Saulo
    Saulo avatar
    3 posts
    Member since:
    Jul 2017

    Posted 11 Oct 2017 in reply to Stefan Link to this post

    This is in c, how do I make it to visual basic?
  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3573 posts

    Posted 12 Oct 2017 Link to this post

    Hello, Saulo,  

    Thank you for writing.  

    Feel free to use our free online converter for converting C# to VB and vice versa: http://converter.telerik.com/

    I would like to note that the GridViewCheckBoxColumn.EditMode property controls when the value of the editor will be submitted to the cell. By default, the current behavior is kept (OnValidate) and the value will be submitted only when the current cell changes or the grid loses focus. The new value (OnValueChange) will submit the value immediately after the editor value changes. Thus, it won't be necessary to call the EndEdit method when the value is toggled. 

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  9. Miklos
    Miklos avatar
    5 posts
    Member since:
    Sep 2015

    Posted 31 Jul 2018 Link to this post

    Hello there,

    I have tried the solution posted by Stefan. In the event the checkbox still has the old value, even after the EndEdit command.

    I need an event of the grid, which fires after a checkbox value is changed, from there I could call a method which uses the values of rows where the checkox is checked. But I need the state after the change has been made.

    Thank you for your answer

  10. Miklos
    Miklos avatar
    5 posts
    Member since:
    Sep 2015

    Posted 31 Jul 2018 in reply to Miklos Link to this post

    I'm sorry! I made a mistake. Its working :)
  11. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3573 posts

    Posted 01 Aug 2018 Link to this post

    Hello, Miklos,    

    If the GridViewCheckBoxColumn.EditMode property is set to OnValueChanged, clicking the checkbox immediately submits the value to the cell. The CellValueChanged event fires when the value of a cell has been changed. Then, you can perform your custom logic.

    I hope this information helps. If you have any additional questions, please let me know.  
     
    Regards,
    Dess
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top