CellClick change the checkbox value

35 posts, 1 answers
  1. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 19 Aug 2014 in reply to Jeen Link to this post

    Hi, everyone.
    I have already solved the problem with unchecking the previously checked checkbox cells by modifying the code provided by Desislava.
    Here is the code snippet modfied:
    ...
    RadCheckBoxEditor cbEditor = sender as RadCheckBoxEditor;
    if ((ToggleState)cbEditor.Value == ToggleState.On)
        {
            checkedRows++;
        }
    else
        {
            if (checkedRows > 0)
                   checkedRows --;
        }
        this.radLabel1.Text = "Checked Rows: " + checkedRows;
    }
    ...

    The only small issue that remains is :   when I check cells from the first down to the last, the counter in the label goes: "0 -> 1 -> 2 -> 3 -> ....." (which is OK). Then I uncheck them from the last up to the first, and the counter goes: ".... -> 3 -> 2 -> 1 -> 0" (also OK). And then I check the first one again, but the counter goes: "0 -> 2 -> 2 -> 3 -> ...." (which is NOT ok).

    Would you be so kind as to hint me on how to solve this, please.
    Thanks a lot in advance.

    Best Regards,
    Jeen
  2. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 21 Aug 2014 Link to this post

    Hello Jeen,

    Thank you for writing back.

    Following the provided code snippet, I modified my sample project. However, I was unable to reproduce the issue you are facing with the latest version Q2 2014 SP1. Here is the code example:
    public Form1()
    {
        InitializeComponent();
     
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("IsActive", typeof(bool));
     
        for (int i = 0; i < 10; i++)
        {
            dt.Rows.Add(i, "Name" + i, false);
        }
     
        this.radGridView1.DataSource = dt;
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    }
     
    private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadCheckBoxEditor cbEditor = e.ActiveEditor as RadCheckBoxEditor;
     
        if (cbEditor != null)
        {
            cbEditor.ValueChanged -= cbEditor_ValueChanged;
            cbEditor.ValueChanged += cbEditor_ValueChanged;
        }
    }
     
    int checkedRows = 0;
     
    private void cbEditor_ValueChanged(object sender, EventArgs e)
        RadCheckBoxEditor cbEditor = sender as RadCheckBoxEditor;
        if ((ToggleState)cbEditor.Value == ToggleState.On)
        {
            checkedRows++;
        }
        else
        {
            if (checkedRows > 0)
                checkedRows --;
        }
        this.radLabel1.Text = "Checked Rows: " + checkedRows;
    }

    The attached gif file illustrates better the obtained behavior. Everything works as expected on my end. Could you please specify the exact steps how to reproduce the problem or get back to me with a sample code snippet, reproducing the issue so I can investigate the precise case? Thank you in advance.

    I am looking forward to your reply.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 22 Aug 2014 in reply to Dess Link to this post

    Hello, Desislava.
    Thank you for your answer!
    In your gif-file it really works as it should.

    In the meantime I have managed to solve the problem in another way, by making another modification and a transposition of a line in the sample code snippet from your previous post.
    Below is the code extract from my project:

    private void cbEditor_ValueChanged(object sender, EventArgs e)
    {
       int counter = 0;
       foreach(GridViewRowInfo row in MyRadGrid.Rows)
          {
               if ((bool)row.Cells["ColumnName"].Value == true)
                    counter++;
          }

        //As you have probably noticed, I have moved this line three lines up, since it didn't  work well for me from where it was before
        RadCheckBoxEditor cbEditor = sender as RadCheckBoxEditor;
        //

        if(counter == MyRadGrid.Rows.Count)
              checkedRows == MyRadGrid.Rows.Count;
       
        if ((ToggleState)cbEditor.Value == ToggleState.On)
        {
            checkedRows++;
        }
        else
        {
            if (checkedRows > 0)
                checkedRows --;
        }
        this.MyLabel1.Text = "Checked Rows: " + checkedRows;
    }
     

    Thanks a lot for your help!
    My problem is finally solved :)

    Best regards,
    Jeen
  5. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 26 Aug 2014 Link to this post

    Hello Jeen,

    Thank you for writing back.

    I am glad that you have found a suitable solution for the specific problem. However, you can find attached my sample project, which behavior is illustrated in the gif file from my previous post.

    If you have any additional questions, please let me know.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  6. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 15 Sep 2014 in reply to Dess Link to this post

    Hello, Desislava.
    Sorry for the delay with the answer (just returned from my vacation).

    Thank you for the sample project zip-file.
    It's always good to know different ways to solve a problem.

    Best regards,
    Jeen
Back to Top
UI for WinForms is Visual Studio 2017 Ready