We decided to implement the grouping UI feature as a separate assembly rather than adding it directly to the C1FlexGrid control for the following reasons:
1) To keep the C1FlexGrid as small, fast, and portable as possible. The Silverlight version of the C1FlexGrid is still under 250k, making it by far the smallest commercially available data grid. It is also the one of the most widely available data grids, with versions for WinForms, Silverlight, WPF, Windows Phone, WinRT, ActiveX, and Compact Framework.
2) To allow for easy customization of the grouping UI. The C1FlexGridGroupPanel is an extremely simple control, and we will make the source code available to users who may want to create customized versions.
3) To demonstrate the extensibility and flexibility of the C1FlexGrid control. The C1FlexGridGroupPanel control was developed using the simple and powerful object model exposed by the C1FlexGrid, without any custom extensions, modifications, or use of internal methods. (The same is true of the C1FlexGridFilter component, which provides ad-hoc filtering and also ships as a separate assembly).
The C1FlexGridGroupPanel is actually a Grid element with a TextBlock that shows the watermark message and a horizontal StackPanel that shows the groups available in the source ICollectionView.
The groups are represented by GroupMarker elements that can be clicked to sort or close the groups, or dragged to re-arrange the grouping order.
The C1FlexGridGroupPanel handles four types of dragging action:
1) Dragging GroupMarkers within the grouping area to re-arrange the groups,
2) Dragging GroupMarkers into the grid to remove the group and restore columns at specific positions,
3) Dragging ColumnHeader elements from the grid to the grouping area to create new groups, and
4) Dragging ColumnHeader elements within the grid to re-arrange the grid columns
All dragging actions are handled by a utility class called DragDropManager.
The first two types of dragging action are initiated by the GroupMarker class, which detects mouse dragging actions and calls the DragDropManager's DoDragDrop method with the marker as a parameter. The last two types of dragging action are initiated in response to the C1FlexGrid's DraggingColumn event.
When the DoDragDrop event is called, the DragDropManager displays a transparent element over the whole page, captures the mouse, and raises the Dragging event so the caller can update the drop location. When the user releases the mouse, the DragDropManager raises the Dropped event so the caller can finish the drag-drop action.
The implementation is very short and portable. The assembly is only about 25k and the code can be built against Silverlight or WPF without any conditional code blocks.