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);
}
} |
dataGrid.AutoExpandGroups = true;
dataGrid.GroupCollapsing += DataGrid_GroupCollapsing;
private void DataGrid_GroupCollapsing(object sender, GroupChangingEventArgs e)
{
e.Cancel = true;
}
|