RadGridView takes 3 times to tick a check box

9 posts, 0 answers
  1. Triet Nguyen Cong
    Triet Nguyen Cong avatar
    78 posts
    Member since:
    Mar 2010

    Posted 22 Aug 2010 Link to this post

    Hi Telerik team,

    Due to our business, we have to build a grid view using AutoGenerateColumns="True".In this grid, we place a check box. But to tick it, we have to click 3 times (attached file):
    - First time, active cell
    - Second time, active check box.
    - Third time, tick on check box. 
    Question is: How can we build a grid which tick check box only one time? And below is our code

    MainPage.xaml
    <UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  
                 x:Class="SilverlightApplication7.MainPage"
        xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
        >
      
        <Grid x:Name="LayoutRoot" Background="White">
            <Controls:RadGridView x:Name="grTest" AutoGenerateColumns="True"></Controls:RadGridView>
        </Grid>
    </UserControl>

    MainPage.xaml.cs
    using System.Collections.Generic;
    using System.Windows.Controls;
      
    namespace SilverlightApplication7
    {
        public partial class MainPage
        {
            public MainPage()
            {
                InitializeComponent();
                var persons = new List<Person> {new Person("Davide Seaman", true), new Person("Roberto Baggio", false)};
                grTest.ItemsSource = persons;
            }
        }
      
        public class Person
        {
            public string Name { get; set; }
            public bool IsMarried { get; set; }
      
            public Person(string name, bool isMarried)
            {
                Name = name;
                IsMarried = isMarried;
            }
        }
    }

    Thanks,

  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 23 Aug 2010 Link to this post

    Hi Triet Nguyen Cong,

    You can set the Snippet EditTriggers property of the gridview to "CellClick". This way - clicking the cell only once will go in edit mode.

    Let me know if this helps.

    Greetings,
    Veselin Vasilev
    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. Triet Nguyen Cong
    Triet Nguyen Cong avatar
    78 posts
    Member since:
    Mar 2010

    Posted 23 Aug 2010 Link to this post

    Hi Veselin Vasilev,

    By using EditTriggers property, we only can reduce 1 time click. That means, to tick a check box, we still have 2 steps:
    - The first click go to edit mode
    - The second click tick to check box.

    Is there any property which we can set to tick to check box with only one click?

    Thanks!
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 23 Aug 2010 Link to this post

    Hi Triet Nguyen Cong,

    There is no such property. What you can do is to define your own cell template and put a checkbox there.
    This way you should be able to check/uncheck with only one click. The downside is that you need to subscribe to the Click event of the checkbox to update the underlying property of your business object.

    <telerik:GridViewColumn Header="IsActive" >
        <telerik:GridViewColumn.CellTemplate>
            <DataTemplate>
                <CheckBox IsChecked="{Binding IsActive}"
                          Click="CheckBox_Click"></CheckBox>
            </DataTemplate>
        </telerik:GridViewColumn.CellTemplate>
    </telerik:GridViewColumn>

    Hope this helps.

    Best wishes,
    Veselin Vasilev
    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
  5. Triet Nguyen Cong
    Triet Nguyen Cong avatar
    78 posts
    Member since:
    Mar 2010

    Posted 24 Aug 2010 Link to this post

    Hi Veselin Vasilev,

    As we mentioned in the first post, we are building a grid with dynamic columns, so we have to use "AutoGeneratedColumns = True" property. This grid is a check box matrix allow user choose. So, we don't think we can use CellTemplate to fix this problem.

    Anyway, thanks for your support!
    Triet
  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 24 Aug 2010 Link to this post

    Hi Triet Nguyen Cong,

    In this case you can define the DataTemplate as a resource and set the CellTemplate in the AutoGeneratingColumn event of the gridview:

    <UserControl.Resources>
      <DataTemplate x:Key="boolDataTemplate">
           <CheckBox IsChecked="{Binding IsActive}" Click="CheckBox_Click"></CheckBox>
      </DataTemplate>
    </UserControl.Resources>


    <telerik:RadGridView ItemsSource="{Binding Clubs}"                                
       AutoGeneratingColumn="RadGridView_AutoGeneratingColumn"/>

    private void RadGridView_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
    {
        if (e.Column.UniqueName == "IsActive")
        {
            e.Column.CellTemplate = this.Resources["boolDataTemplate"] as DataTemplate;
        }
    }

    This way you will still have the columns autogenerated.

    Kind regards,
    Veselin Vasilev
    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
  7. Valentin Raceanu
    Valentin Raceanu avatar
    10 posts
    Member since:
    Jun 2012

    Posted 04 Feb 2011 Link to this post

    Looks like there is a simpler solution now than defining a custom cell: http://www.telerik.com/help/wpf/gridview-checkbox-column.html
  8. Alfons
    Alfons avatar
    14 posts
    Member since:
    Mar 2012

    Posted 08 Nov 2012 Link to this post

    Thanks Valentin, for the tip.
    But is it also possible to set AutoSelectOnEdit="True" when AutoGenerateColumns="True"?
  9. Yoan
    Admin
    Yoan avatar
    1215 posts

    Posted 09 Nov 2012 Link to this post

    Hello Alfons,

    Indeed, it is possible. Please check this help article, which describes the approach.

    Don't hesitate to contact us if you have other questions.

    Greetings,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top