GridViewCheckBoxColumn Cick Event

9 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    141 posts
    Member since:
    Apr 2011

    Posted 30 Aug Link to this post

    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

  2. özer
    özer avatar
    22 posts
    Member since:
    Jun 2020

    Posted 30 Aug in reply to pierre-jean Link to this post

    Have you tried handling the ValueChanged event? 

     

  3. özer
    özer avatar
    22 posts
    Member since:
    Jun 2020

    Posted 30 Aug in reply to özer Link to this post

    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();
        }
    }
  4. özer
    özer avatar
    22 posts
    Member since:
    Jun 2020

    Posted 30 Aug in reply to özer Link to this post

    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();
        }
    }
  5. pierre-jean
    pierre-jean avatar
    141 posts
    Member since:
    Apr 2011

    Posted 30 Aug in reply to özer Link to this post

    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.

  6. pierre-jean
    pierre-jean avatar
    141 posts
    Member since:
    Apr 2011

    Posted 30 Aug in reply to pierre-jean Link to this post

    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

  7. özer
    özer avatar
    22 posts
    Member since:
    Jun 2020

    Posted 31 Aug in reply to pierre-jean Link to this post

    You're welcome, I'm glad I could help.
  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 02 Sep Link to this post

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

  9. pierre-jean
    pierre-jean avatar
    141 posts
    Member since:
    Apr 2011

    Posted 02 Sep in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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

Back to Top