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

Check only one checkbox in GridViewCheckBoxColumn

6 Answers 309 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tijana
Top achievements
Rank 1
Tijana asked on 17 Oct 2014, 12:04 PM
Hello,

By default, GridViewCheckBoxColumn allows for multiple checked checkboxes, but I need to allow the user to check only one checkbox at a time.

Could you please advise how to do that?

Thank you.

6 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 17 Oct 2014, 12:07 PM
Hi,

You can use our Select Column instead of GridViewCheckBox column. Please check this help article for a reference.

Regards,
Yoan
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.

 
0
Tijana
Top achievements
Rank 1
answered on 17 Oct 2014, 12:42 PM
Thank you, but Select colum is not what I'm looking for, because I need to bind data to it.
I have 3 boundable GridViewCheckBox columns in the same grid and I can allow user to check only one check box in each column.
Is there a way to do this with GridViewCheckBox column?
0
Yoan
Telerik team
answered on 17 Oct 2014, 12:47 PM
Hello,

Indeed, GridViewSelectColumn is bound internally to IsSelected property of GridViewRow. However, you can check this example which demonstrates how to bind GridViewRow's IsSelected property to a property of your business object. I believe that this will help you to achieve your requirement.

As a side note - Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our SDK Samples Browser. You can also use it to review the examples.

Regards,
Yoan
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.

 
0
Tijana
Top achievements
Rank 1
answered on 17 Oct 2014, 01:49 PM
Problem is that I have 3 columns with checkboxes in the same grid.
If I use Select column, by selecting row, all 3 check boxes within this row will be checked and this is not my itention.
These 3 GridViewCheckBox columns are independent of each other.

On the other side I need to bind values from 3 columns, but I have the only one IsSelected property of GridViewRow.
Any suggestion from your side will be appreciated.
0
Tijana
Top achievements
Rank 1
answered on 20 Oct 2014, 01:10 PM
Any news on this topic?
0
Yoan
Telerik team
answered on 21 Oct 2014, 04:38 PM
Hi,

You can try other approach - define a Checkbox in the CellEditTemplate of the column. Then you can use its Checked event and loop through the items and update the boolean property. Please check the following code snippet:
<telerik:GridViewDataColumn DataMemberBinding="{Binding IsActive}">
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding IsActive,Mode=TwoWay}" Checked="CheckBox_Checked" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                                      .
                                      .
                                      .
private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            foreach (var club in (this.clubsGrid.ItemsSource as ObservableCollection<Club>))
            {
                if (club.IsActive && club != (this.clubsGrid.SelectedItem as Club))
                {
                    club.IsActive = false;
                }
            }
        }

I hope this helps.

Regards,
Yoan
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.

 
Tags
GridView
Asked by
Tijana
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Tijana
Top achievements
Rank 1
Share this question
or