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

Checkbox click

14 Answers 1294 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Henk Wallinga
Top achievements
Rank 1
Henk Wallinga asked on 15 Apr 2010, 09:29 AM

Hi,
I have a gridview with cells bound to a datasource. In addition I added a checkboxcolumn as follows:

 

this

 

.radGVMeldinger.MasterGridViewTemplate.Columns.Add(new GridViewCheckBoxColumn());

I want this grid not editable, only the checkbox.
I made the following code snippet:

 

private

 

void radGVMeldinger_CellClick(object sender, GridViewCellEventArgs e)

 

{

 

    if (e.RowIndex >= 0)

 

    {

 

        if (this.radGVMeldinger.MasterGridViewTemplate.Rows[e.RowIndex].Cells[12].Value.ToString() != "True")

 

        {

            radGVMeldinger.MasterGridViewTemplate.Rows[e.RowIndex].Cells[12].Value =

true;

 

        }

 

        else

 

 

 

 

        {

            radGVMeldinger.MasterGridViewTemplate.Rows[e.RowIndex].Cells[12].Value =

false;

 

        }

    }

}

 

Everything works fine, unless the fact that when I click the checkbox column this event doesn't fire.
This event fires when I click on every other column.
Has anyone a solution?
Regards,
/Henk

14 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 15 Apr 2010, 10:00 AM
Hello Henk Wallinga,

This event doesn't fire for checkbox cells because they contain a permanent editor which catches this event. You should use the GridViewColumn.ReadOnly property to specify which columns are read only.

 

Greetings,
Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Massimo
Top achievements
Rank 1
answered on 23 Oct 2010, 05:16 PM
I have the same problem: I have a checkbox column, it's the only one editable column (not read only). The ValueChanged and/or the cellValueChanged not fires.
I need to know if on my grid I have some line checked but I can't.
I try using a timer (!!!!) to count the checked lines every second, and I see that if I stay on the checked line it's counted as not checked... I need to move on another line to see the change!!
Some help?
0
Emanuel Varga
Top achievements
Rank 1
answered on 23 Oct 2010, 08:32 PM
Hello Marco,

The ValueChanged event will fire every time you change the value in a cell, but that value will not be applied in the cell until you move from that cell, because it is waiting for confirmation, you could always cancel the operation, or change the value.
That's why when you move out of that cell, and the value has been changed, the CellValueChanged event will fire, and the value will be changed.
You can change this behavior by registering to the ValueChanged event and using this:
void radGridView1_ValueChanged(object sender, EventArgs e)
{
    // this will end the edit operation and force a value change to occur
    radGridView1.EndEdit();
    // uncomment this line if you want to be in editing mode after the value change
    // radGridView1.BeginEdit();
}

I will also attach a full example in the following lines, if you need it:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
 
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.Dock = DockStyle.Fill;
        radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
        var list = new List<Test>();
        for (int i = 0; i < 10; i++)
        {
            list.Add(new Test { Id = i, Checked = i % 2 == 0 });
        }
 
        radGridView1.ValueChanged += new EventHandler(radGridView1_ValueChanged);
        radGridView1.CellValueChanged += new GridViewCellEventHandler(radGridView1_CellValueChanged);
        radGridView1.DataSource = list;
    }
 
    void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
    {
        Debug.WriteLine("CellValueChanged");
    }
 
    void radGridView1_ValueChanged(object sender, EventArgs e)
    {
        Debug.WriteLine("ValueChanged");
        radGridView1.EndEdit();
        //radGridView1.BeginEdit();
    }
}
 
public class Test
{
    public int Id { get; set; }
 
    public bool Checked { get; set; }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Massimo
Top achievements
Rank 1
answered on 25 Oct 2010, 09:47 AM
Great! It works!!!
Thank you very much!
0
Rama Krishna
Top achievements
Rank 1
answered on 12 Dec 2012, 09:26 PM
Hello,

I have the same problem. I have a radgridview that will autofilled by datasource from database. one of the column in binary so it will automatically creates a checkbox column. My requirement is to switch between select and deselect of the checkbox if user clicks on any part of that row. I am able to capture the cellclick event when users click anywhere on the row except the checkbox cell. I would like to know how can I capture cellclick event when user clicks on a checkbox cell.

Thanks in advance!
Rama
0
Svett
Telerik team
answered on 17 Dec 2012, 05:55 PM
Hello Rama,

I did not manage to reproduce the issue with the latest release Q3 2012 SP1. The CellClick event is fired when the checkbox editor is clicked. Could you share more information regarding the version that you are using and how you initialize and use RadGridView?

Greetings,
Svett
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Rama Krishna
Top achievements
Rank 1
answered on 02 Jan 2013, 09:58 PM
Hello Svett,

I think I am using Q1 2012 SP1. I am initializing the Radgridview by executing a storedprocedure and assinging result as datasource. I am not having any pre added columns to the radgriedview.
One of the columns in the result set is binary which automatically converted to checkbox column on Radgridview after binding. I am trying to check and uncheck the checkbox based on cellclick event, but auto genereated Checkbox column is not responding to the cellclick event. I think I need to use the latest release.

Thanks,
Rama
0
Svett
Telerik team
answered on 07 Jan 2013, 12:10 PM
Hi Rama,

Thank you for writing.

I did not manage to reproduce the issue with 2012.1.321.40 (Q1 2012 SP1). It seems that there is something specific that I am missing. Could you send a sample project where the issue occurs? This will help us to understand your scenario from first hand.

Kind regards,
Svett
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Marc
Top achievements
Rank 1
Veteran
answered on 19 Dec 2017, 11:54 AM

I'm using the EndEdit()-Method with my CheckBox.

But there is one issue:

If I clicked the same cell/CheckBox, I got an error: ASSERT - Trying to update row outside a transaction!

Can you please help me :)

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Dec 2017, 12:11 PM
Hello, Marc, 

Thank you for writing.  

We haven't had similar reports for RadGridView from other customers. Instead of calling EndUpdate for the grid, I would recommend you to set the GridViewCheckBoxColumn.EditMode  property to OnValueChange. Thus, the editor of the GridViewCheckBoxColumn won't be activated and the value will be immediately submitted to the cell.

If you are still experiencing any further difficulties, feel free to submit a support ticket providing a sample project demonstrating the problem. Thus, our support staff will gladly assist you.

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
Marc
Top achievements
Rank 1
Veteran
answered on 19 Dec 2017, 12:19 PM

Hey Dess,

thank you, changing the EditMode to OnValueChange works fine.

But I have still the same problem with the ASSERT-issue when I'm clicking the same checkbox a second time, without changing the row.
I'm using ProBindingSource.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Dec 2017, 12:31 PM
Hello, Marc, 

Thank you for writing back. 

It seems that you use RadGridView in an OpenEdge environment. Please note that for OpenEdge related topics the preferred places to submit a technical question are Salesforce and the Progress Community. You can log in to these websites straight from your Progress account: https://progresslink.progress.com/supportlink.

In case the issue persists please open a case in Salesforce and send us your project so that we can test it locally.

I hope this helps. Let me know if you have other questions.

 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
Pixie
Top achievements
Rank 1
answered on 13 Jun 2019, 04:57 AM

I have a similar problem. I have set the editmode of the column to onvaluechange and now the CellValueChanged event fires as soon as the checkbox is checked. However what I want to do is

1. When the checkbox is ticked, do some validation

2. If the validation fails, untick the messagebox and have this take effect immediately, without the user having to exit the cell.

Part 1 is working fine, but if I set the cell's value to false in the CellValueChanged event, it doesn't untick the checkbox until the user exits the cell. And if I try using the CellValidating event, it doesn't fire until the user exits the cell.

How can I do part 2?

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Jun 2019, 09:59 AM
Hello, Pixie,          

Note that the CellValueChanged event is fired after the cell's value has been changed. The CellValidating event is raised by RadGridView when the current cell changes or when the cell loses input focus (when pressing Enter key). If the same cell is still focused, the CellValidating event is not appropriate for this case.

public RadForm1()
{
    InitializeComponent();
    this.radGridView1.CellFormatting += radGridView1_CellFormatting;
}
 
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridCheckBoxCellElement checkBoxCell = e.CellElement as GridCheckBoxCellElement;
    if (checkBoxCell != null)
    {
        checkBoxCell.Editor.ValueChanging -= Editor_ValueChanging;
        checkBoxCell.Editor.ValueChanging += Editor_ValueChanging;
    }
}
 
private void Editor_ValueChanging(object sender, ValueChangingEventArgs e)
{
    Console.WriteLine(e.NewValue);
    if (RadMessageBox.Show("Are you sure?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
    {
        e.Cancel = true;
        this.radGridView1.EndEdit();
    }
}

You can handle the GridCheckBoxCellElement.Editor.ValueChanging event in order to control whether the value will be changed or not. Please refer to the following code snippet:

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
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
Henk Wallinga
Top achievements
Rank 1
Answers by
Jack
Telerik team
Massimo
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Rama Krishna
Top achievements
Rank 1
Svett
Telerik team
Marc
Top achievements
Rank 1
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Pixie
Top achievements
Rank 1
Share this question
or