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

Inserting Checkbox in header of gridviewcheckboxcolumn

7 Answers 334 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jeff torririt
Top achievements
Rank 1
jeff torririt asked on 14 Jan 2010, 02:05 AM
Hi,

I need to place a checkbox in a header of a gridviewcheckboxcolumn of radgridview. for obvious reason. how can i do it in rad gridview?

Thanks

7 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Jan 2010, 09:13 AM
Hi jeff,

Please look at this KB article. It demonstrates how to implement the desired scenario. If you have other questions, we will be glad to assist you.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
jeff torririt
Top achievements
Rank 1
answered on 28 Jan 2010, 03:43 AM
Thanks.. my problem now is how can i uncheck the checkbox in the header when i unchecked one of the checkboxes in the gridviewcheckboxcolumn..

Many Thanks,

Jeff
0
Jack
Telerik team
answered on 28 Jan 2010, 09:49 AM
Hi jeff torririt,

You can handle ValueChanged event and when the editor value is false set the column header checkbox to false too. Please consider the following code, I modified some of the methods of CheckBoxHeaderCell from the KB:

 

bool suspendToggleStateChanged;
 
public override void Initialize()
{
    base.Initialize();
    ApplyThemeToElement(checkbox, "ControlDefault");
    this.GridControl.ValueChanged += new EventHandler(GridControl_ValueChanged);
}
 
void GridControl_ValueChanged(object sender, EventArgs e)
{
    RadCheckBoxEditor editor = sender as RadCheckBoxEditor;
    if (editor != null && (bool)editor.Value == false)
    {
        suspendToggleStateChanged = true;
        checkbox.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off;
        suspendToggleStateChanged = false;  
    }
}
 
private void checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
    if (suspendToggleStateChanged)
    {
        return;
    }
    if (this.ColumnInfo is GridViewCheckBoxColumn)
    {
        bool valueState = false;
 
        if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
        {
            valueState = true;
        }
 
        for (int i = 0; i < this.ViewTemplate.RowCount; i++)
        {
            this.ViewTemplate.Rows[i].Cells[this.ColumnIndex].Value = valueState;
        }
    }
}

 

Sincerely yours,
Jack
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
jeff torririt
Top achievements
Rank 1
answered on 29 Jan 2010, 09:41 AM
Many thanks.

Jeff
0
Trinh
Top achievements
Rank 1
answered on 04 Oct 2012, 08:50 AM
Well, I have a problem with RadGridView, grid have one column grouped. The select all check box has no effect.
Could anyone help me?? Thank a lot
0
Jack
Telerik team
answered on 08 Oct 2012, 02:32 PM
Hello Trinh,

When using code from this KB article you should change the checkbox_ToggleStateChanged method to cover the described scenario. Consider the following code:
private void checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
    if (!suspendProcessingToggleStateChanged)
    {
        bool valueState = false;
 
        if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
        {
            valueState = true;
        }
        this.GridViewElement.EditorManager.EndEdit();
        this.TableElement.BeginUpdate();
 
        IterateRows(this.ViewInfo.ChildRows, valueState);
 
        this.TableElement.EndUpdate(false);
 
        this.TableElement.Update(GridUINotifyAction.DataChanged);
 
    }
}
 
void IterateRows(GridViewChildRowCollection rows, bool valueState)
{
    for (int i = 0; i < rows.Count; i++)
    {
        if (rows[i] is GridViewDataRowInfo)
        {
            rows[i].Cells[this.ColumnIndex].Value = valueState;
        }
        else
        {
            IterateRows(rows[i].ChildRows, valueState);
        }
    }
}

If you have other questions, do not hesitate to contact us.
 
All the best,
Jack
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Trinh
Top achievements
Rank 1
answered on 09 Oct 2012, 09:38 AM
It works, thank a lot..........
Tags
GridView
Asked by
jeff torririt
Top achievements
Rank 1
Answers by
Jack
Telerik team
jeff torririt
Top achievements
Rank 1
Trinh
Top achievements
Rank 1
Share this question
or