GridviewCheckBoxColumn check value incorrect when using shorcutkey for button

3 posts, 1 answers
  1. Selvamani
    Selvamani avatar
    7 posts
    Member since:
    Nov 2011

    Posted 04 Nov 2011 Link to this post

    Hi,

        i have created a sample application to produce the bug. the application contains gridview with one cell which is gridviewcheckcolumn and a rad button to show the messagebox saying whether the check box is checked or not in the gridview.
        
        when i check the checkbox and if i press the button mesage box showing checked but when i press shortcut key for the button its not working correctly.

        there is a scenarion in my project where we have shortcut key for the button and it behaves like as i said above, so any suggestions on this regard will be helpful for me to solve this issue

    private void Form1_Load(object sender, EventArgs e)
           {
               GridViewDataRowInfo row = this.radGridView1.Rows.AddNew();
           }
     
           private void radButton1_Click(object sender, EventArgs e)
           {
               string name = radGridView1.Rows[0].Cells[0].Value.ToString();
               if (radGridView1.Rows[0].Cells["Select"].Value.ToString() == "True")
                   MessageBox.Show("Checked");
               else
                   MessageBox.Show("UnChecked");          
           }

    Thanks,
    Selva
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 10 Nov 2011 Link to this post

    Hi Selvamani,

    Thank you for writing.

    The reason for the observed behavior is caused by the fact that when you click the check box, the check box editor is still in edit mode and executing the shortcut of the button, will not get its new value. While, when you press the button, the grid looses focus, the editor is closed, and the new value is submitted. This is why you are getting correct value.

    In order to make both cases working, subscribe to the ValueChanged event of RadGridView and if the CurrentColumn is your check box column, call the EndEdit method of RadGridView:
    void radGridView1_ValueChanged(object sender, EventArgs e)
    {
        if (radGridView1.CurrentColumn.Name == "Select")
        {
            radGridView1.EndEdit();
        }
    }

    I hope that you find this information helpful. 
     
    Kind regards,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. Selvamani
    Selvamani avatar
    7 posts
    Member since:
    Nov 2011

    Posted 10 Nov 2011 Link to this post

    Hi,

        its working fine now. thanks for the kind suggestion.

    regard's
    Selva
Back to Top