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

RadGridView takes 3 times to tick a check box

8 Answers 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Triet Nguyen Cong
Top achievements
Rank 2
Triet Nguyen Cong asked on 22 Aug 2010, 08:44 AM
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,

8 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 23 Aug 2010, 08:32 AM
Hi Triet Nguyen Cong,

You can set the 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
0
Triet Nguyen Cong
Top achievements
Rank 2
answered on 23 Aug 2010, 11:20 AM
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!
0
Veselin Vasilev
Telerik team
answered on 23 Aug 2010, 04:08 PM
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
0
Triet Nguyen Cong
Top achievements
Rank 2
answered on 24 Aug 2010, 08:08 AM
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
0
Veselin Vasilev
Telerik team
answered on 24 Aug 2010, 12:51 PM
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
0
Valentin Raceanu
Top achievements
Rank 1
answered on 04 Feb 2011, 04:21 PM
Looks like there is a simpler solution now than defining a custom cell: http://www.telerik.com/help/wpf/gridview-checkbox-column.html
0
Alfons
Top achievements
Rank 2
answered on 08 Nov 2012, 02:31 PM
Thanks Valentin, for the tip.
But is it also possible to set AutoSelectOnEdit="True" when AutoGenerateColumns="True"?
0
Yoan
Telerik team
answered on 09 Nov 2012, 01:35 PM
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.

Tags
GridView
Asked by
Triet Nguyen Cong
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Triet Nguyen Cong
Top achievements
Rank 2
Valentin Raceanu
Top achievements
Rank 1
Alfons
Top achievements
Rank 2
Yoan
Telerik team
Share this question
or