This is a migrated thread and some comments may be shown as answers.

GridView CheckBox CellValueChanged

10 Answers 509 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vasilis
Top achievements
Rank 1
Vasilis asked on 11 Jan 2012, 01:26 PM
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

10 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 16 Jan 2012, 11:39 AM
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).

0
Vasilis
Top achievements
Rank 1
answered on 23 Jan 2012, 02:31 PM
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 ? 
0
Julian Benkov
Telerik team
answered on 26 Jan 2012, 10:01 AM
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).

0
Vasilis
Top achievements
Rank 1
answered on 26 Jan 2012, 02:59 PM
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.


0
Julian Benkov
Telerik team
answered on 31 Jan 2012, 02:59 PM
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).

0
Saulo
Top achievements
Rank 1
answered on 11 Oct 2017, 03:26 PM
This is in c, how do I make it to visual basic?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Oct 2017, 08:41 AM
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.
0
Miklos
Top achievements
Rank 1
answered on 31 Jul 2018, 01:44 PM

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

0
Miklos
Top achievements
Rank 1
answered on 31 Jul 2018, 02:06 PM
I'm sorry! I made a mistake. Its working :)
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Aug 2018, 08:31 AM
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.
Tags
GridView
Asked by
Vasilis
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Vasilis
Top achievements
Rank 1
Julian Benkov
Telerik team
Saulo
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Miklos
Top achievements
Rank 1
Share this question
or