We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Option to not (!) expand/collapse group in SfDataGrid on Single Click

Thread ID:

Created:

Updated:

Platform:

Replies:

125105 Jul 21,2016 12:39 PM Jul 28,2016 01:28 AM WPF 7
loading
Tags: SfDataGrid
Bernd
Asked On July 21, 2016 12:39 PM

Hi,

is there a way to disable the behaviour of expanding/collapsing groups in a SfDataGrid with a single click. I would like to only expand/collapse by clicking on the symbol in column 0 or by double click.

How do I do that?

Regards
Bernd


Sowndaiyan Paulpandi [Syncfusion]
Replied On July 22, 2016 09:28 AM

Hi Bernd,

Thank you for contacting Syncfusion support. 

 
We have checked your query. You can achieve your requirement by override the OnPreviewMouseLeftButtonUp and OnPreviewMouseDoubleClick methods on CaptionSummaryRowControl class like the below code example.

C#
 

public
partial class MainWindow : Window 
    { 
        public MainWindow() 
        { 
            InitializeComponent(); 
           this.sfgrid.RowGenerator = new CustomRowGenerator(this.sfgrid); 
        } 
 
    } 



 

public
class CustomRowGenerator : RowGenerator 
    { 
        public CustomRowGenerator(SfDataGrid dataGrid) 
            : base(dataGrid) 
        { 
        } 
 
        protected override VirtualizingCellsControl GetVirtualizingCellsControl<T>() 
        { 
            if (typeof(T) == typeof(CaptionSummaryRowControl)) 
            { 
                CustomCaptionSummaryRowControl rowcontrol = new CustomCaptionSummaryRowControl(); 
                rowcontrol.sfDataGrid = this.Owner; 
                return rowcontrol; 
            } 
            return base.GetVirtualizingCellsControl<T>(); 
        } 
    } 
 
    public class CustomCaptionSummaryRowControl : CaptionSummaryRowControl 
    { 
        public SfDataGrid sfDataGrid; 
 
        public CustomCaptionSummaryRowControl() 
            : base() 
        { 
            this.DefaultStyleKey = typeof(CustomCaptionSummaryRowControl); 
        } 
 
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) 
        { 
            var visualContainer = sfDataGrid.GetVisualContainer() as VisualContainer; 
            var index = visualContainer.PointToCellRowColumnIndex(e.GetPosition(null)); 
            if (e.ClickCount == 1 && index.ColumnIndex != 0) 
                return; 
            base.OnPreviewMouseLeftButtonUp(e); 
        } 
        protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e) 
        { 
            if (this.DataContext is Group) 
            { 
                var group = this.DataContext as Group; 
                if (group.IsExpanded) 
                    sfDataGrid.CollapseGroup(group); 
                else 
                    sfDataGrid.ExpandGroup(group); 
            } 
            base.OnPreviewMouseDoubleClick(e); 
        } 
    } 


We have prepared the sample as per your requirements and you download the same from the below location,

Sample : http://www.syncfusion.com/downloads/support/forum/125105/ze/Grouping47763116

Regards,

Sowndaiyan
 


Sivakumar R [Syncfusion]
Replied On July 23, 2016 01:26 PM

Hi Bernd, 
 
Your requirement can be achieved by handling GroupCollapsing event also. Please refer the below code snippet, 
 
dataGrid.AutoExpandGroups = true; 
dataGrid.GroupCollapsing += DataGrid_GroupCollapsing; 
 
private void DataGrid_GroupCollapsing(object sender, GroupChangingEventArgs e) 
{ 
    e.Cancel = true; 
} 
 
 
UG links: 
 
Thanks, 
Sivakumar 


Bernd
Replied On July 25, 2016 07:42 AM

Sowndaiya,

thank you for the sample. It works mostly like expected but it also blocks the single click on the adorner which I'd like to still respond to a single click.

Regards
Bernd

Bernd
Replied On July 25, 2016 07:43 AM

Sivakumar,

thank you for the suggestion but this blocks collapsing in general which is not the goal.

Regards
Bernd

Sowndaiyan Paulpandi [Syncfusion]
Replied On July 26, 2016 11:55 AM

Hi Bernd, 

We have checked your reported problem and its working fine in our side. Is it possible to share simple sample to replicate the issue or please modify the our previous provided sample as per your application and revert back to us

Regards,


Sowndaiyan


Bernd
Replied On July 27, 2016 04:32 PM

Sowndaiyan,

I have to aplogize. You sample is behaving perfectly well. I don't know what I did the last time...

Thank you
Bernd

Sowndaiyan Paulpandi [Syncfusion]
Replied On July 28, 2016 01:28 AM

Hi Bernd,

Thanks for your update.

We are glad that our sample helped you resolving your issue. Please let us know if you need any other assistance.

Regards,

Sowndaiyan


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;