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

EnableHeaderCheckBox

1 Answer 267 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Claude asked on 18 Dec 2014, 02:10 PM
I wish to use the EnableHeaderCheckBox in my grid view but cancel its action under certain conditions (should not select/unselect all if a custom condition is true).  How can I do that?
In the HeaderCellToggleStateChanged, there is no Cancel action in the GridViewHeaderCellEventArgs.

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 19 Dec 2014, 04:53 PM
Hello Claude,

Thank you for writing.

You can reach this kind of behavior by using the Enabled property of the CheckBox object of the GridCheckBoxHeaderCellElement:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
 
    bool flag = false;
    void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridCheckBoxHeaderCellElement headerCell = e.CellElement as GridCheckBoxHeaderCellElement;
        if (headerCell != null)
        {
            headerCell.CheckBox.Enabled = flag;
        }
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        this.productsTableAdapter.Fill(this.nwindDataSet.Products);
 
        var checkboxColumn = this.radGridView1.Columns["YourCheckBoxColumn"] as GridViewCheckBoxColumn;
        checkboxColumn.EnableHeaderCheckBox = true;
 
        radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
    }
 
    private void radButton1_Click(object sender, EventArgs e)
    {
        flag = !flag;
        radGridView1.MasterView.TableHeaderRow.InvalidateRow();
 
        radButton1.Text = flag.ToString();
    }
}

I hope that this information is useful. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or