EnableHeaderCheckBox

2 posts, 0 answers
  1. Claude
    Claude avatar
    9 posts
    Member since:
    Dec 2014

    Posted 18 Dec 2014 Link to this post

    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.
  2. Hristo
    Admin
    Hristo avatar
    1508 posts

    Posted 19 Dec 2014 Link to this post

    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.

     
Back to Top