Grouping in ComponentOne FlexGrid for WPF is implemented with the help of C1FlexGridGroupPanel. When grouping is applied on C1FlexGrid then a new grouping area is exposed in the header with a watermark informing you to drag and drop a column there to group by that column. It is possible to group by multiple columns simply by dragging a second ColumnHeader onto the grouping area.

The C1FlexGridGroupPanel is an extremely simple to use control which allows for easy customization of the grouping. We have had quite a few customers with the specific user scenario wherein they want to hide a specific column group marker of their choice from the C1FlexGridGroupPanel but still have it as GroupDescriptions to keep the grouping.

With this blog, we will explain an approach to hide a specific column from C1FlexGridGroupPanel while dragging but still have it as GroupDescriptions to keep the grouping.



For hiding a certain column, for example 'Line' column in the C1FlexGridGroupPanel, we need to get the StackPanel object inside C1FlexGridGroupPanel, and control the visiblity of StackPanel's children.

The code snippet implements the same:-


StackPanel _panel;
void myGroupPanel_Loaded(object sender, RoutedEventArgs e)
{
_panel = FindChild<StackPanel>(myGroupPanel, string.Empty);
_panel.LayoutUpdated += _panel_LayoutUpdated;
}
void _panel_LayoutUpdated(object sender, EventArgs e)
{
if (_panel.Children.Count > 0)
{
foreach (FrameworkElement item in _panel.Children)
{
PropertyGroupDescription description =
GetModelValue("PropertyGroupDescription", item) as PropertyGroupDescription;

if (description != null && description.PropertyName == "Line")
{
item.Visibility = System.Windows.Visibility.Hidden;
break;
}
}
}
}
public object GetModelValue(string FieldName, object obj)
{
try
{
Type Ts = obj.GetType();
object output = Ts.GetProperty(FieldName).GetValue(obj, null);
return output;
}
catch
{
return null;
}
}

private T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
{
// Confirm parent and childName are valid.
if (parent == null) return null;

T foundChild = null;

int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
// If the child is not of the request child type child
T childType = child as T;
if (childType == null)
{
// recursively drill down the tree
foundChild = FindChild<T>(child, childName);

// If the child is found, break so we do not overwrite the found child.
if (foundChild != null) break;
}
else if (!string.IsNullOrEmpty(childName))
{
var frameworkElement = child as FrameworkElement;
// If the child's name is set for search
if (frameworkElement != null && frameworkElement.Name == childName)
{
// if the child's name is of the request name
foundChild = (T)child;
break;
}
}
else
{
// child element found.
foundChild = (T)child;
break;
}
}

return foundChild;
}


On running the sample, when you drag the 'Line' column to C1FlexGridGroupPanel, then 'Line' ColumnHeader will be hidden in C1FlexGridGroupPanel. Other columns will show up in C1FlexGridGroupPanel.

Like this, various other customizations can also be implemented.

This brings us to the end of one particular user scenario. There may be many others as well. We are open to your suggestions and implementation of additional user scenarios. We would be happy to look into them :)

Download Sample