Use checkbox to select items

5 posts, 1 answers
  1. Clint Singer
    Clint Singer avatar
    133 posts
    Member since:
    Oct 2012

    Posted 21 Jun 2010 Link to this post

    Hi,

    In Windows 7 (maybe Vista too) there is an explorer feature found int the "Folder Options" called "Use check boxes to select items" which lets the user (un)select files using the traditional methods or checkboxes. 

    I am trying to emulate that feature using the GridView but I haven't figured out how to bind the checkbox to the rows selection state. 

    Ideally, one the row/checkbox selection should also be tied to the SelectedItems property of the Grid so that it can be used in the code behind to select the row and cause the checkbox to update.

    I would really appreciate an example about how to solve this problem.

    Cheers,
    Clint
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 22 Jun 2010 Link to this post

    Hello,

     Why not use GridViewSelectColumn directly? You can check this demo for more info.

    Best wishes,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Clint Singer
    Clint Singer avatar
    133 posts
    Member since:
    Oct 2012

    Posted 23 Jun 2010 Link to this post

    Thanks!

    I am not sure how I missed that one for so long.

    Cheers,
    Clint
  5. v-govinr@microsoft.com
    v-govinr@microsoft.com avatar
    18 posts
    Member since:
    Jun 2010

    Posted 19 Jul 2010 Link to this post

    Hi,
    Can you tell me how can I databind to GridViewselectcolumn or if I have bool type cinded to GridViewDataColumn then how to provide SeelectAll checkbox in Header

    Thanks
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Jul 2010 Link to this post

    Hi v-govinr@microsoft.com,

    GridViewSelectColumn is bound to the property of the GridViewRow - IsSelected. As a result it cannot be related to another custom property of your own.
    What you can do in this case is to define a GridViewCheckBoxColumn, bind it to the property you want and predefine its Header. For instance:

    <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsPlaying}">
        <telerik:GridViewCheckBoxColumn.Header>
            <CheckBox telerik:StyleManager.Theme="Office_Black" Click="CheckBox_Click" />
        </telerik:GridViewCheckBoxColumn.Header>
    </telerik:GridViewCheckBoxColumn>

    On the click event you need to add the logic for SelectAll and UnselectAll:
    private void CheckBox_Click(object sender, System.Windows.RoutedEventArgs e)
            {
                var checkBox = sender as CheckBox;
                if (checkBox != null)
                {
                    if (checkBox.IsChecked.GetValueOrDefault())
                    {
                        this.playersGrid.SelectAll();
                    }
                    else
                    {
                        this.playersGrid.UnselectAll();
                    }
                }
            }

    And last but not least, you need to add a custom behavior that will be responsible for all the selection of the items.
    I am sending you a sample project illustrating the proposed solution. 

     


    Greetings,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner