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

Detect changes in Gridview

3 Answers 20 Views
This is a migrated thread and some comments may be shown as answers.
Eusebio
Top achievements
Rank 1
Veteran
Eusebio asked on 19 Nov 2020, 09:13 AM

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.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Nov 2020, 01:28 PM

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/.

0
Eusebio
Top achievements
Rank 1
Veteran
answered on 23 Nov 2020, 11:32 AM

Thanks,

But...Do you have some code please?

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Nov 2020, 01:14 PM

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/.

Asked by
Eusebio
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Eusebio
Top achievements
Rank 1
Veteran
Share this question
or