Checkbox click

15 posts, 1 answers
  1. Henk Wallinga
    Henk Wallinga avatar
    1 posts
    Member since:
    Apr 2010

    Posted 15 Apr 2010 Link to this post

    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

  2. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 15 Apr 2010 Link to this post

    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.
  3. Marco
    Marco avatar
    3 posts
    Member since:
    Jul 2010

    Posted 23 Oct 2010 Link to this post

    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?
  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 23 Oct 2010 Link to this post

    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
  5. Marco
    Marco avatar
    3 posts
    Member since:
    Jul 2010

    Posted 25 Oct 2010 Link to this post

    Great! It works!!!
    Thank you very much!
  6. Rama Krishna
    Rama Krishna avatar
    2 posts
    Member since:
    Jul 2012

    Posted 12 Dec 2012 Link to this post

    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
  7. Svett
    Admin
    Svett avatar
    728 posts

    Posted 17 Dec 2012 Link to this post

    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.
  8. Rama Krishna
    Rama Krishna avatar
    2 posts
    Member since:
    Jul 2012

    Posted 02 Jan 2013 Link to this post

    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
  9. Svett
    Admin
    Svett avatar
    728 posts

    Posted 07 Jan 2013 Link to this post

    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.
  10. Marc
    Marc avatar
    48 posts
    Member since:
    Mar 2017

    Posted 19 Dec 2017 Link to this post

    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 :)

  11. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3276 posts

    Posted 19 Dec 2017 Link to this post

    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.
  12. Marc
    Marc avatar
    48 posts
    Member since:
    Mar 2017

    Posted 19 Dec 2017 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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.

  13. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3276 posts

    Posted 19 Dec 2017 Link to this post

    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.
  14. Pixie
    Pixie avatar
    4 posts
    Member since:
    May 2013

    Posted 12 Jun in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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?

     

  15. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3276 posts

    Posted 17 Jun Link to this post

    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.
Back to Top