this.datagrid.GroupColumnDescriptions.CollectionChanged += GroupColumnDescriptions_CollectionChanged;
this.datagrid.ItemsSourceChanged += Datagrid_ItemsSourceChanged;
//Hides indent columns if you have grouped while loading by adding GroupColumnDescriptions
private void Datagrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)
{
if (e.NewItemsSource != null)
this.HideIndentColumns();
}
//Hides indents columns when grouping at runtime
private void GroupColumnDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
this.HideIndentColumns();
}
private void HideIndentColumns()
{
if (this.datagrid.View == null)
return;
this.datagrid.Dispatcher.BeginInvoke(new Action(() =>
{
int start = this.datagrid.ShowRowHeader ? 1 : 0;
for (int i = start; i < this.datagrid.GroupColumnDescriptions.Count + start; i++)
{
this.datagrid.GetVisualContainer().ColumnWidths[i] = 0;
}
}), DispatcherPriority.ApplicationIdle);
}
|