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

Use checkbox to select items

4 Answers 127 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Clint Singer
Top achievements
Rank 1
Clint Singer asked on 21 Jun 2010, 10:23 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 22 Jun 2010, 06:33 AM
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
0
Clint Singer
Top achievements
Rank 1
answered on 23 Jun 2010, 05:30 PM
Thanks!

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

Cheers,
Clint
0
v-govinr@microsoft.com
Top achievements
Rank 1
answered on 19 Jul 2010, 06:14 AM
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
0
Maya
Telerik team
answered on 19 Jul 2010, 06:47 PM
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
Tags
GridView
Asked by
Clint Singer
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Clint Singer
Top achievements
Rank 1
v-govinr@microsoft.com
Top achievements
Rank 1
Maya
Telerik team
Share this question
or