Checkbox in grouprow of gridview disappears or moves when scolling

1 Answer 68 Views
GridView
Nico
Top achievements
Rank 1
Nico asked on 01 Mar 2023, 11:20 AM | edited on 03 Mar 2023, 11:13 AM

Dear sir/madam,

I used your solution for adding a checkbox in grouprows of a grid for UI Winforms:

winforms-sdk/GridView/GridCheckAllGroupRows at master · telerik/winforms-sdk · GitHub

Only specific grouprows need a checkbox, not all grouprows, which I handle in the CreateCell event. So far so good, seems to work perfect.

But.... when I start scrolling in the grid, because not all grouprows are visible in one screen, and the grouprows that have a checkbox leave the screen because of scrolling down, and then scrolling up again, the checkbox in the grouprow is gone, and grouprows that did not have the checkbox have now a checkbox?

Strange, I cannot figure out what is going wrong.

Hopefully  I succeeded in describing the situation clearly.
Help would be appreciated.

Kind regards.

 

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 03 Mar 2023, 02:15 PM

Hello Nico,

Thank you for the provided details. This behavior is due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping, and so on. This means that only the data underneath the cells is changed. What you can do here is handle this in the custom group cell SetContent() method. You can hide or show the checkbox by setting the Visibility property to true. However, this approach would be possible if you can access all required data in the CustomGridGroupContentCellElement class. For example:

public override void SetContent()
{
    base.SetContent();
    this.DrawText = false;
    textElement.Text = ((GridViewGroupRowInfo)this.RowInfo).HeaderText;
    checkBoxElement.CheckStateChanged -= checkBoxElement_CheckStateChanged;
    if (this.RowInfo.Tag != null)
    {
        checkBoxElement.Checked = (bool)this.RowInfo.Tag;
    }
    else
    {
        checkBoxElement.Checked = false;
    }
    checkBoxElement.CheckStateChanged += checkBoxElement_CheckStateChanged;
    if (this.RowIndex  % 2 != 0)
    {
        this.checkBoxElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
    }
    else
    {
        this.checkBoxElement.Visibility = Telerik.WinControls.ElementVisibility.Visible;
    }
}

Using this above code, the CheckBoxElement is hiding on specific rows.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Nico
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or