Updating C1DataGrid group header information

Posted by: Swapnil.Walwadkar on 19 December 2023, 4:59 pm EST

  • Posted 19 December 2023, 4:59 pm EST - Updated 19 December 2023, 5:09 pm EST

    Hello ComponentOne team,

    we have a c1Datagrid and have populated rows in the same. We have grouping of rows with below code snippet:

    <CollectionViewSource.GroupDescriptions>





    </CollectionViewSource.GroupDescriptions>

    Refer [Img2] if above snippet is not completely visible.

    Now we have a requirement that once a group is collapsed we want to display some additional information in that group header as shown in attached image.

    So could you please provide us with inputs on how to we can edit group header?

  • Posted 21 December 2023, 12:24 pm EST

    Hi Swapnil,

    Unfortunately, there is no direct way to handle the expansion/collapse of C1DataGrid’s group row. However, you can subscribe to C1DataGrid’s PreviewMouseDown event as shown in the following code snippet to achieve the desired behavior:

    private void DataGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        var ele = dataGrid.InputHitTest(e.GetPosition(this)) as FrameworkElement;
        if (ele != null && ele.TemplatedParent.GetType() == typeof(DataGridToggleGroupButton))
        {
            DataGridToggleGroupButton toggleButton = ele.TemplatedParent as DataGridToggleGroupButton;
            var rowPresenter = toggleButton.TemplatedParent as DataGridGroupRowPresenter;
            var textblock = rowPresenter.GroupContent as TextBlock;
            if (toggleButton.IsChecked == true && textblock != null)
            {
                textblock.Text = textblock.Text + ": Additional data";
            }
            else if(toggleButton.IsChecked == false && textblock != null)
            {
                textblock.Text = textblock.Text.Substring(0, textblock.Text.IndexOf(':') );
            }
        }
    }

    Kindly refer to the attached sample for full implementation. See DataGridGroupHeader.zip

    Thanks & Regards,

    Aastha

  • Posted 3 January 2024, 8:29 pm EST - Updated 3 January 2024, 8:34 pm EST

    Hello ComponentOne team,

    Thank you for the solution. We are now able to provide our custom information to group header.

    However, in your provided sample solution, if we scroll down and then up using mouse wheel (we can reduce the height of window so that we can scroll) the customised text added in C1DataGrid’s group row header disappears and we see only the original value.

    [Image1] is the screenshot for the same.

    Could you please guide us how to resolve this issue?

  • Posted 4 January 2024, 8:37 pm EST

    Hi Swapnil,

    The issue occurs because the C1DataGrid is re-rendered on scrolling and the group header text is set according to the DataContext bound to it. Therefore, in order to achieve the desired behavior, you need to manage a collection of the collapsed GroupRows.

    We have updated the previous sample for demonstration. Kindly refer DataGridGroupHeader_Mod.zip

    Thanks & Regards,

    Aastha

  • Posted 23 January 2024, 4:22 pm EST

    Hello ComponentOne team,

    Thank you for the sample.

    In the provided sample as well, if their is no vertical scrollbar (increase height of window) and if we scroll mousewheel on grid, the addional information dissapears.

    Could you please provide inputs on how to handle this situation?

  • Posted 27 January 2024, 12:07 am EST

    Hi Swapnil,

    The desired behavior can be achieved by refreshing the datagrid while handling its MouseWheel event as shown in the following code snippet:

    dataGrid.MouseWheel += (s,e) =>
    {
    	dataGrid.Refresh();
    };

    Kindly refer to the attached sample for full implementation. See DataGridGroupHeader_Mod2.zip.

    Thanks & Regards,

    Aastha

  • Posted 29 January 2024, 3:50 pm EST

    Hello ComponentOne Team,

    Thank you so much for the inputs. Your provided solution seems to works fine as expected.

    However, we just wanted to check can their be a simpler solution for this if we upgrade to latest version of C1dataGrid (Currently we are using 4.0 version).

    We are concerned that this implementation will hit performance (loading time of grid) as we have around 2K rows in the grid and this addtional info of group gets updated on regular basis (whever user updates child row info).

    Please let us know your best suggestion and recomendation on this.

  • Posted 30 January 2024, 4:48 pm EST

    Hi Swapnil,

    C1DataGrid is a legacy control and is not under development. We recommend you upgrade to the C1FlexGrid control, which has more features and better performance. You can find the documentation for C1FlexGrid here:

    Documentation link to C1FlexGrid: https://developer.mescius.com/componentone/docs/wpf/online-flexgrid/overview.html

    Please note that there is no direct tool to migrate from C1DataGrid to C1FlexGrid. Due to the differences in the APIs of the two, you’ll need to manually implement the features in C1FlexGrid that you were using in C1DataGrid.

    If you have any questions or problems during the process of migration, please feel free to raise a query.

    Thanks & Regards,

    Aastha

  • Posted 1 February 2024, 11:14 pm EST

    Hello Component One Team,

    Thank you for the inputs.

    So could you please let me know if i use FlexGrid of version 4.0, will i get better solution for this issue?

    Will it be possible to provide sample code fulfilling the same requirement using flexgrid? This will give us better idea on flexgrid.

    Based on your inputs we can then decide if we can manually move from C1datagrid to C1flexgrid.

  • Posted 5 February 2024, 1:01 pm EST

    Hi Swapnil,

    You can used custom group header converters to achieve the desired behavior in C1FlexGrid. Here is the code snippet for the same:

    [code]public class UserGroupHeaderConverter : IValueConverter

    {

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

    var grpRow = parameter as GroupRow;

    var val = value as CollectionViewGroup;

    if(grpRow != null && grpRow.IsCollapsed && val.Name==“SubGroup 1”)

    {

    return val.Name + “:Additional Information”;

    }

    return val.Name;

    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    

    }[/code]

    FlexGrid 4.0 is in maintenance mode and out of support now. Therefore, we would suggest you use the latest version of the flexgrid control to get the latest features and updates. We have attached the sample containing 4.6.20233.804 flexgrid control implementation for the requirement. See GrpHeaderContent.zip

    If you face any challenges during the migration process, feel free to create a new support case if you have a different/new requirement. This will help us better manage and address your specific issues.

    Thanks & Regards,

    Aastha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels