Unplanned
Last Updated: 28 Feb 2018 11:41 by ADMIN
ADMIN
Ivan Todorov
Created on: 07 Jun 2012 02:53
Category:
Type: Feature Request
6
ADD. RadListView - add checkboxes to the header and to its group visual items which will check/uncheck all the child items.
It would be more convenient to the end user to have a single checkbox in the header of RadListView(DetailsView) which will check/uncheck all the items in RadListView. Also, the group items should have a checkbox which checks/unchecks all the items in that group.
1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 28 Feb 2018 11:41
Currently, the possible solution is to use the following code snippet:

       private RadCheckBoxElement checkBox;

        public RadForm1()
        {
            InitializeComponent();

            this.radListView1.DataSource = this.productsBindingSource;
            this.radListView1.ViewType = ListViewType.DetailsView;
            this.radListView1.ShowCheckBoxes = true;

            this.checkBox = new RadCheckBoxElement();
            this.checkBox.Margin = new Padding(0, 10, 0, 0);
            this.checkBox.ToggleStateChanged += new StateChangedEventHandler(checkBox_ToggleStateChanged);
            this.radListView1.ItemCheckedChanged += new ListViewItemEventHandler(radListView1_ItemCheckedChanged);
            this.checkBox.ZIndex = 1000;
            this.checkBox.Alignment = ContentAlignment.TopLeft;
            this.checkBox.StretchHorizontally = this.checkBox.StretchVertically = false;
            this.checkBox.IsThreeState = true;
            this.radListView1.ListViewElement.Children.Add(this.checkBox);
        }

        private void checkBox_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
            if (this.checkBox.ToggleState == ToggleState.Indeterminate)
            {
                this.checkBox.ToggleState = ToggleState.Off;
                return;
            }
            this.radListView1.BeginUpdate();
            this.radListView1.ItemCheckedChanged -= new ListViewItemEventHandler(radListView1_ItemCheckedChanged);

            foreach (ListViewDataItem item in this.radListView1.Items)
            {
                item.CheckState = this.checkBox.ToggleState;
            }
            this.radListView1.EndUpdate();
            this.radListView1.ItemCheckedChanged += new ListViewItemEventHandler(radListView1_ItemCheckedChanged);
        }

        private void radListView1_ItemCheckedChanged(object sender, ListViewItemEventArgs e)
        {
            this.checkBox.ToggleStateChanged -= new StateChangedEventHandler(checkBox_ToggleStateChanged);
            ToggleState checkState = ToggleState.Off;

            for (int i = 0; i < this.radListView1.Items.Count; i++)
            {
                if (i == 0)
                {
                    checkState = this.radListView1.Items[0].CheckState;
                }
                else if (this.radListView1.Items[i].CheckState != this.radListView1.Items[i - 1].CheckState)
                {
                    checkState = ToggleState.Indeterminate;
                    break;
                }
            }

            this.checkBox.ToggleState = checkState;

            this.checkBox.ToggleStateChanged += new StateChangedEventHandler(checkBox_ToggleStateChanged);

            this.radListView1.ListViewElement.SynchronizeVisualItems();
        }

       private RadCheckBoxElement checkBox;

        public RadForm1()
        {
            InitializeComponent();

            this.radListView1.DataSource = this.productsBindingSource;
            this.radListView1.ViewType = ListViewType.DetailsView;
            this.radListView1.ShowCheckBoxes = true;

            this.checkBox = new RadCheckBoxElement();
            this.checkBox.Margin = new Padding(0, 10, 0, 0);
            this.checkBox.ToggleStateChanged += new StateChangedEventHandler(checkBox_ToggleStateChanged);
            this.radListView1.ItemCheckedChanged += new ListViewItemEventHandler(radListView1_ItemCheckedChanged);
            this.checkBox.ZIndex = 1000;
            this.checkBox.Alignment = ContentAlignment.TopLeft;
            this.checkBox.StretchHorizontally = this.checkBox.StretchVertically = false;
            this.checkBox.IsThreeState = true;
            this.radListView1.ListViewElement.Children.Add(this.checkBox);
        }

        private void checkBox_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
            if (this.checkBox.ToggleState == ToggleState.Indeterminate)
            {
                this.checkBox.ToggleState = ToggleState.Off;
                return;
            }
            this.radListView1.BeginUpdate();
            this.radListView1.ItemCheckedChanged -= new ListViewItemEventHandler(radListView1_ItemCheckedChanged);

            foreach (ListViewDataItem item in this.radListView1.Items)
            {
                item.CheckState = this.checkBox.ToggleState;
            }
            this.radListView1.EndUpdate();
            this.radListView1.ItemCheckedChanged += new ListViewItemEventHandler(radListView1_ItemCheckedChanged);
        }

        private void radListView1_ItemCheckedChanged(object sender, ListViewItemEventArgs e)
        {
            this.checkBox.ToggleStateChanged -= new StateChangedEventHandler(checkBox_ToggleStateChanged);
            ToggleState checkState = ToggleState.Off;

            for (int i = 0; i < this.radListView1.Items.Count; i++)
            {
                if (i == 0)
                {
                    checkState = this.radListView1.Items[0].CheckState;
                }
                else if (this.radListView1.Items[i].CheckState != this.radListView1.Items[i - 1].CheckState)
                {
                    checkState = ToggleState.Indeterminate;
                    break;
                }
            }

            this.checkBox.ToggleState = checkState;

            this.checkBox.ToggleStateChanged += new StateChangedEventHandler(checkBox_ToggleStateChanged);

            this.radListView1.ListViewElement.SynchronizeVisualItems();
        }