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
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).
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 ?
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).
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.
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.
Julian Benkov
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
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
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
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.
Dess
Progress Telerik