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

Check box cells update only after moving rows :(

2 Answers 122 Views
GridView
This is a migrated thread and some comments may be shown as answers.
chris petropoulos
Top achievements
Rank 1
chris petropoulos asked on 11 May 2010, 06:23 PM
Hi guys,

Im sure there is some obvious im missing, but the problem i have is that i have a grid with 3 columns. Column 1 has report name, Column 2 - a checkbox column to 'show' that report, Column 3 - a checkbox column to 'hide' that report. So if a user clicks the checkbox in 'Show' column, i want to uncheck the 'Hide' checkbox column (ie column 2) and vice versa. The code below handles it, however the grid only refreshes the change once i move off the current row... So what do i need to call so that the cells or row is repainted instantly once this code runs? Also should i instead use the CellValueChanged event? coz that didnt seem to work, hence why i chose this event here. Also do i even need to call BeginEdit and EndEdit here? Im not quite sure when those methods should be used.

Thanks for your advice :-) Chris.

private void gridReport_ValueChanged(object sender, EventArgs e)
        {
            RadCheckBoxEditor editor = (RadCheckBoxEditor)sender;
            editor.BeginEdit();
            SUB_REPORT report = (SUB_REPORT)gridReport.CurrentCell.RowInfo.DataBoundItem;
            if (gridReport.CurrentCell.ColumnIndex == 1) // show column
            {
                if ((bool)editor.Value)
                {
                    report.Hide = false;
                }
            }
            else
            {
                if ((bool)editor.Value)
                {
                    report.Show = false;
                }
            }
            editor.EndEdit();           
        }                 

2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 12 May 2010, 01:15 PM
Hello chris petropoulos,

You can use the following code in this case:

void radGridView1_ValueChanged(object sender, EventArgs e)
{
    RadCheckBoxEditor editor = sender as RadCheckBoxEditor;
    if (editor != null)
    {
        GridViewDataColumn column = (GridViewDataColumn)this.radGridView1.CurrentColumn;
        if (column.UniqueName == "Bool")
        {
            this.radGridView1.CurrentRow.Cells["Bool2"].Value = !(bool)editor.Value;
        }
        if (column.UniqueName == "Bool2")
        {
            this.radGridView1.CurrentRow.Cells["Bool"].Value = !(bool)editor.Value;
        }
    }
}

You don't have to call BeginEdit or EndEdit methods. These methods are used to open or close the editor thru code. In addition the following KB article demonstrates how to place radio buttons in a single cell. I hope it helps.

Kind regards,
Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
chris petropoulos
Top achievements
Rank 1
answered on 25 May 2010, 05:06 AM
Thanks for the quick answer. it worked perfectly :-) Tell your boss you deserve a pay rise :-)
Tags
GridView
Asked by
chris petropoulos
Top achievements
Rank 1
Answers by
Jack
Telerik team
chris petropoulos
Top achievements
Rank 1
Share this question
or