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

GridViewCheckBoxColumn Cick Event

8 Answers 8 Views
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 30 Aug 2020, 10:24 AM

Hello

I have a gridview in which I have added a GridViewCheckBoxColumn

I have not found which event is fired when I click on the check box and how to get the value of the checkbos (checked or not) without leaving the cell.

In other word how can I catch the click on the check bos and test its value.
the CellValueChanged event is fired only when I leave the cell ...
the CellClick Event allows me to get the cell but not the checkbox value ..

Any idea ?

Thanks in advance

8 Answers, 1 is accepted

Sort by
0
özer
Top achievements
Rank 1
Veteran
answered on 30 Aug 2020, 04:08 PM

Have you tried handling the ValueChanged event? 

 

0
özer
Top achievements
Rank 1
Veteran
answered on 30 Aug 2020, 04:08 PM
private void radGridView1_ValueChanged(object sender, EventArgs e)
{
    string msg = "";
    try
    {
        if (radGridView1.ActiveEditor is RadCheckBoxEditor && radGridView1.CurrentCell.RowIndex >= 0)
        {
             
                if (checkState == "On")
                {
                    // do something
                }
                else if (checkState == "Off")
                {
                    // do something
                }
        }
    }
    catch (Exception ex)
    {
        msg = ex.Message.ToString();
    }
}
0
özer
Top achievements
Rank 1
Veteran
answered on 30 Aug 2020, 04:11 PM

I forgot to add where the value checkState comes from.

private void radGridView1_ValueChanged(object sender, EventArgs e)
{
    string msg = "";
    try
    {
        if (radGridView1.ActiveEditor is RadCheckBoxEditor && radGridView1.CurrentCell.RowIndex >= 0)
        {
            string checkState = rgvReportList.ActiveEditor.Value.ToString();
                if (checkState == "On")
                {
                    // do something
                }
                else if (checkState == "Off")
                {
                    // do something
                }
        }
    }
    catch (Exception ex)
    {
        msg = ex.Message.ToString();
    }
}
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 30 Aug 2020, 04:26 PM

Hello thanks for your information

Yes I have tried the valuechanged event, but is is fired when I "leave" the cell that contains the CheckBox, I would like an event that is fired when I click the checkbox, without leaving the cell and a property that tells me if the checkbox is checked or not.

0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 30 Aug 2020, 05:06 PM

OK thanks to your input I found the solution:

1. I Declare a checkEditor
    Private WithEvents Checkeditor As RadCheckBoxEditor

2. In the CellEditorInitialized event I instanciate the checkbox

    If TypeOf e.ActiveEditor Is RadCheckBoxEditor Then
            Checkeditor = e.ActiveEditor
     End If

3. The CheckEditor has an event ValueChanged that is fired a every click in the check box and
the checkeditor.value property is "off" or "on", combined with the grid currentrow I have all I need

 

Thanks for your suggestions that have sent me in the right direction

Best Regards

0
özer
Top achievements
Rank 1
Veteran
answered on 31 Aug 2020, 11:10 AM
You're welcome, I'm glad I could help.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Sep 2020, 10:26 AM
Hello, guys,
 
I am glad that you have discussed the scenario with clicking a cell inside a GridViewCheckBoxColumn

However, please have in mind that the GridViewCheckBoxColumn offers the EditMode property. This property determines whether changing a value of a check box will immediately be send to the cell (OnValueChange) or when the current cell is changed or the grid is being validated (OnCellChangeOrValidating). Feel free to set the EditMode property to OnValueChange and handle the CellValueChanged event. In this case, the event will be fired as soon as you click a checkbox.

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

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 02 Sep 2020, 10:35 AM

Hello Dess

Thanks for this complement of information, it clearly is a more straight forward mechanism to handle the Click Event on the checkBox.

I will modify my code to handle the click event as you suggest

Best Regards

Pierre-Jean

Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
özer
Top achievements
Rank 1
Veteran
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or