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

[Solved] Having to click twice on checkbox in GridView

4 Answers 727 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hector
Top achievements
Rank 1
Hector asked on 12 Jun 2009, 03:07 PM
Hello.  I have a GridView with a column as a checkbox bound to the IsSelect property of the DataRow.  For some reason, to click on the checkbox to select the row, I have to click twice.  It seems to me that the first click is setting the focus on the cell clicked, then the second click actually checks the checkbox. 
Ideally, I would like to get rid of the checkbox and be able to select multiple rows by just clickin on the rows, but without having to press the Control or Shift keys.  Clicking each row would be like having the Ctrl key pressed.  I tried implementing this by adding a function on the row mousedown event, however this would unselect the previous selected rows.

Does anyone have any suggestions?  Here is part of my code:
Page.xaml
<telerikGridView:RadGridView Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"    
                                    x:Name="gridMultiSelect_accounts" ColumnsWidthMode="Auto"   
                                    Width="auto" Height="330" VerticalGridlinesBrush="Transparent"   
                                    UseAlternateRowStyle="True" AutoGenerateColumns="False" ShowGroupPanel="False" 
                                    MultipleSelect="True" Margin="5,5,5,5" > 
                                      
                                    <telerikGridView:RadGridView.Columns > 
                                        <telerikGridView:GridViewColumn HeaderText="Select">  
                                            <telerikGridView:GridViewColumn.CellTemplate> 
                                                <DataTemplate> 
                                                    <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Loaded="CheckBox_Loaded"/>  
                                                </DataTemplate> 
                                            </telerikGridView:GridViewColumn.CellTemplate> 
                                        </telerikGridView:GridViewColumn> 
                                        <telerikGridView:GridViewDataColumn HeaderText="Phone" UniqueName="Value"/>  
                                        <telerikGridView:GridViewDataColumn HeaderText="Account Description" UniqueName="Description"/>  
                                        <telerikGridView:GridViewDataColumn HeaderText="Group" UniqueName="GroupName"/>  
                                    </telerikGridView:RadGridView.Columns> 
                                </telerikGridView:RadGridView> 

Page.xaml.cs:
private void Page_Loaded(object sender, RoutedEventArgs e)  
        {  
            var proxy = new PortalService.PortalDB_serviceClient();  
            proxy.GetAccountValidValuesCompleted += new EventHandler<GetAccountValidValuesCompletedEventArgs>(proxy_GetAccountValidValuesCompleted);  
            proxy.GetAccountValidValuesAsync(_appID);  
            // Set up GridView group on GroupName column  
            RadGroupDescription groupDescription = new RadGroupDescription();  
            groupDescription.PropertyName = "GroupName";  
            gridMultiSelect_accounts.GroupDescriptions.Add(groupDescription);  
            gridMultiSelect_accounts.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(gridMultiSelect_accounts_SelectionChanged);  
            gridMultiSelect_accounts.RowLoaded += new EventHandler<RowLoadedEventArgs>(gridMultiSelect_accounts_RowLoaded);  
   
        }  
 
        void gridMultiSelect_accounts_RowLoaded(object sender, RowLoadedEventArgs e)  
        {  
            e.Row.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(Row_MouseLeftButtonUp);  
        }  
 
        void Row_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)  
        {  
            GridViewRowItem row = (GridViewRowItem)sender;  
            row.IsSelected = !row.IsSelected;  
        }  
private IList<AccountValidValues> _AccountValidValues;  
        private IList<string> _AccountNames, _SortFields;  
        void proxy_GetAccountValidValuesCompleted(object sender, GetAccountValidValuesCompletedEventArgs e)  
        {  
            gridMultiSelect_accounts.Items.Clear();  
            _AccountValidValues = e.Result;  
            gridMultiSelect_accounts.ItemsSource = _AccountValidValues;  
              
        } 

4 Answers, 1 is accepted

Sort by
0
Hector
Top achievements
Rank 1
answered on 12 Jun 2009, 06:23 PM
I figured out the multiple click on check box issue.  This is a bug that was addressed in the latest release.  I got a latest RadGridViiew.dll and it works. 
I would still like to find out if it is possible to be able to click on the rows to select multiple rows without having to press the shift or control keys.
Thanks.
0
Accepted
Milan
Telerik team
answered on 17 Jun 2009, 07:57 AM
Hello Hector,

The multiple selection that you are describing is not supported by RadGridView at the moment. I have prepared a sample application that implements such functionality but the implementation is now straightforward and involves creating custom row style and writing some code.

Such builtin multiple selection is on our todo list but I am not sure when we will be able to introduce it.

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Hector
Top achievements
Rank 1
answered on 17 Jun 2009, 03:22 PM
Thanks, Millan.  Seeing your code gave me a way of doing without using all the custom row styling.  Here is my code and it works great.  When you click on a row, it selects it, if it is already selected, it will deselect it.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Documents;  
using System.Windows.Input;  
using System.Windows.Media;  
using System.Windows.Media.Animation;  
using System.Windows.Shapes;  
using System.Windows.Data;  
using Telerik.Windows.Controls;  
using Telerik.Windows.Controls.GridView;  
using Telerik.Windows.Data;  
 
namespace SilverlightApplication2  
{  
    public partial class Page : UserControl  
    {  
        List<MyObject> _selectedObjects = new List<MyObject>();  
        public Page()  
        {  
            InitializeComponent();  
 
            RadGridView1.ItemsSource = from i in Enumerable.Range(0, 10)  
                                       select new MyObject()  
                                       {  
                                           ID = i,  
                                           Name = String.Format("Name{0}", i)  
                                       };  
            RadGridView1.RowLoaded += new EventHandler<RowLoadedEventArgs>(RadGridView1_RowLoaded);  
            RadGridView1.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(RadGridView1_SelectionChanged);  
        }  
 
        void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)  
        {  
            foreach (var item in e.RemovedRecords)  
            {  
                DataRecord dr = (DataRecord)item;  
                MyObject myObject = (MyObject)dr.Data;  
                if (_selectedObjects.Contains(myObject))  
                {  
                    item.IsSelected = true;  
                }  
            }  
        }  
 
        void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)  
        {  
            e.Row.MouseLeftButtonUp += new MouseButtonEventHandler(Row_MouseLeftButtonUp);  
        }  
 
        void Row_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)  
        {  
            GridViewRowItem row = (GridViewRowItem)sender;  
            if (row == null)  
                return;  
            DataRecord dr = (DataRecord)row.Record;  
            MyObject myObject = (MyObject)dr.Data;  
            if (_selectedObjects.Contains(myObject)) //If row already in selection, then deselect it  
            {  
                _selectedObjects.Remove(myObject);  
                row.IsSelected = false;  
            }  
            else //else add it to the selection  
            {  
                _selectedObjects.Add(myObject);  
 
            }  
 
        }  
    }  
 
    public class MyObject  
    {  
        public int ID { get; set; }  
        public string Name { get; set; }  
    }  
}  
 
0
Milan
Telerik team
answered on 18 Jun 2009, 05:39 AM
Hello Hector,

Thanks for sharing your improved version.

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Hector
Top achievements
Rank 1
Answers by
Hector
Top achievements
Rank 1
Milan
Telerik team
Share this question
or