Check only one checkbox in GridViewCheckBoxColumn

7 posts, 0 answers
  1. Tijana
    Tijana avatar
    6 posts
    Member since:
    Oct 2014

    Posted 17 Oct 2014 Link to this post

    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.
  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 17 Oct 2014 Link to this post

    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.

     
  3. DevCraft banner
  4. Tijana
    Tijana avatar
    6 posts
    Member since:
    Oct 2014

    Posted 17 Oct 2014 in reply to Yoan Link to this post

    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?
  5. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 17 Oct 2014 Link to this post

    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.

     
  6. Tijana
    Tijana avatar
    6 posts
    Member since:
    Oct 2014

    Posted 17 Oct 2014 in reply to Yoan Link to this post

    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.
  7. Tijana
    Tijana avatar
    6 posts
    Member since:
    Oct 2014

    Posted 20 Oct 2014 in reply to Yoan Link to this post

    Any news on this topic?
  8. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 21 Oct 2014 Link to this post

    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.

     
Back to Top
DevCraft banner