Checkbox in header to check all items

4 posts, 0 answers
  1. Timo
    Timo avatar
    5 posts
    Member since:
    Jan 2012

    Posted 04 Jun 2012 Link to this post

    Hi all,

    I'm looking for a possibility to add a checkbox in the header of a listview (DetailsView) to check all items in the view.
    Furthermore, I'm using grouping and would like to add a checkbox to each "group" to check all related items of this group.
    The 'ShowCheckBoxes' property is already enabled, but it's poor to select each item.

    I'm using WinForms 2012 1 321.

    Thanks in advanced !

    Regards
    Timo
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 07 Jun 2012 Link to this post

    Hi Timo,

    Thank you for contacting us.

    I agree that such feature will make RadListView more convenient to use when the check boxes are turned on. Therefore, I have logged this as a feature request in our Public Issue Tracking System. Here you can find the PITS item. We will consider addressing this in a future release.

    For the time being, you can achieve this by extending the base functionality of RadListView. For further details, please refer to the attached project.

    Your Telerik points have been updated for the feature request.

    Should you have any further questions, feel free to ask.

    All the best,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Timo
    Timo avatar
    5 posts
    Member since:
    Jan 2012

    Posted 10 Jun 2012 Link to this post

    Hi Ivan,

    thanks for the example code, it works fine.
    It would be great if this functionality will be supported by default in one of the next releases.

    I have additional questions:
    1. You are using custom grouping in your example. Does custom grouping support automated grouping or it's necessary to add the items manually to the group ?

    2. I changed the column header text during runtime but I don't see any changes. The header text which was set during initialization of the list view is always displayed. Do I need to call any update method ?

    3. After clearing the Items list I expect that also the SelectedItems and CheckedItems lists are cleared. But the lists still contain items. When I try to clear CheckedItems list then the program freez. Any idea ?

    Thanks
    Timo
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 12 Jun 2012 Link to this post

    Hi Тimo,

    When you are using custom grouping, you always need to assign a given item to its group manually. If you are using a data source, you can use the ItemDataBound event to assign the new item to its group. Alternatively, you can group your data according to the values of a column. This is achieved by using GroupDescriptors and in this case EnableGrouping should be set to true and EnableCustomGrouping to false. More information about grouping can be found in this help article.

    As to changing the caption of a column, yes, you should do a manual update after you change the HeaderText:
    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radListView1.Columns[1].HeaderText = "Some Text";
        DetailListViewElement viewElement = ((DetailListViewElement)this.radListView1.ListViewElement.ViewElement);
        foreach (DetailListViewCellElement headerCell in viewElement.ColumnContainer.Children)
        {
            headerCell.Synchronize();
        }
    }

    However, this is not the desired behavior and the text should automatically update when you change it. Therefore, I have logged this to PITS as an issue and we will address it in a future release. Here is the link to the PITS item. Your Telerik points have been updated.

    As to your last question, there are known issues regarding this behavior that were previously logged. Here are the links to the PITS items: http://www.telerik.com/support/pits.aspx#/public/winforms/10902, http://www.telerik.com/support/pits.aspx#/public/winforms/10903. We will do our best to address these issues for the next service pack. For the time being, here is how you can workaround this:
    private void ClearItems()
    {
        this.radListView1.SelectedItem = null;
        this.radListView1.BeginUpdate();
     
        ListViewDataItem[] checkedItems = new ListViewDataItem[this.radListView1.CheckedItems.Count];
        this.radListView1.CheckedItems.CopyTo(checkedItems, 0);
     
        foreach (ListViewDataItem item in checkedItems)
        {
            item.CheckState = ToggleState.Off;
        }
     
        this.radListView1.EndUpdate();
        this.radListView1.Items.Clear();
    }

    I hope this will help you. Do not hesitate to write back if you have any additional questions.

    Regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top