Detect changes in Gridview

4 posts, 0 answers
  1. Eusebio
    Eusebio avatar
    44 posts
    Member since:
    Aug 2020

    Posted 19 Nov 2020 Link to this post

    Hi,

     

    I am using the ValueChanged event to detect changes in the grid that contains Checkboxes and I assign true to a variable which I use later to ask if it is true. But if with a second click I return to its previous value, the value has not really changed. How do I detect if something has really changed in the grid?

     

    This is my code:

     

            private void rgvPerfiles_ValueChanged(object sender, EventArgs e)
            {                                                                         
                if (this.rgvPerfiles.ActiveEditor is RadCheckBoxEditor)
                {
                    hayCambiosPendientes = true;
                }
            }

    Best regards.

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 19 Nov 2020 Link to this post

    Hi, Eusebio,

    The RadGridView.ValueChanged event is expected to fired when the value in the editor is updated. However, this editor's value is not committed to the cell yet until you press Enter or navigate to another cell.

    For the GridViewCheckBoxColumn it is convenient to specify its EditMode property to OnValueChange.Thus, the value will be committed to the associated cell as soon as you toggle the checkbox. In this case, the CellValueChanged event is fired indicating that the cell has a new value. Please give this approach a try and see how it works in your scenario.

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Eusebio
    Eusebio avatar
    44 posts
    Member since:
    Aug 2020

    Posted 23 Nov 2020 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks,

    But...Do you have some code please?

     

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 24 Nov 2020 Link to this post

    Hello, Eusebio,    

    I have prepared a sample code snippet for your reference:

            public RadForm1()
            {
                InitializeComponent();
    
                GridViewCheckBoxColumn checkBoxColumn = new GridViewCheckBoxColumn("CheckBox column");
                checkBoxColumn.EditMode = EditMode.OnValueChange;
                checkBoxColumn.Width = 100;
                radGridView1.MasterTemplate.Columns.Add(checkBoxColumn);
    
                for (int i = 0; i < 10; i++)
                {
                    this.radGridView1.Rows.Add(false);
                }
    
                this.radGridView1.CellValueChanged += radGridView1_CellValueChanged;
            }
    
            private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
            {
                if (e.Column is GridViewCheckBoxColumn)
                {
                    object cellValue = e.Row.Cells[e.Column.Name].Value;
                    RadMessageBox.Show(cellValue + "");
                }
            }

    I believe that you will it useful for achieving your goal.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top