Add IsRemovable to GridViewColumn?

1 Answer 20 Views
GridView
Arthur
Top achievements
Rank 1
Iron
Iron
Iron
Arthur asked on 26 Nov 2021, 10:47 AM

Hello,

I have a RadGridView with a fixed set of columns that exist at the start of the app.

I'm also adding new columns to the grid dynamically at runtime depending on user input.

Sometimes, I need to clear all the dynamically created columns.

So I quickly came with a system that keeps tracks of the fixed columns. That way, I can clear all columns then re-create the fixed ones.

I also could have the other way around by keeping track of the created columns and just clear these ones.

But in both ways, I think the problem could be more elegantly solved if GridViewColumn had a property like IsRemovable, or a method CanRemove that I could set to true for my dynamic columns, and false for my fixed columns, so that when I clear my columns, I don't have any extra code to write to get the behavior I want.

Does it sound relevant to you? Do you think of another method/workaround?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 01 Dec 2021, 07:59 AM

Hello Arthur,

To achieve the wanted behavior, you could extend the functionality of the existing column types that the RadGridView control uses. For example, you could create a new class that derives from the GridViewColumn class, and add the IsRemovable property. On the manually defined columns you could set this property as follows:

<telerik:RadGridView.Columns>
    <local:CustomDataColumn Header="Club Name" IsRemovable="False"/>
    <local:CustomDataColumn Header="Established" IsRemovable="False"/>
    <local:CustomDataColumn Header="Capacity" IsRemovable="False"/>
</telerik:RadGridView.Columns>

The definition of the CustomDataColumn column is as follows:

public class CustomDataColumn : GridViewColumn
{
    public bool IsRemovable { get; set; }
}

Alternatively, if the aforementioned approach is undesired, you could use the Tag property, which is of type object, and you could set it False for the static columns and True for the dynamic ones.

<telerik:RadGridView.Columns>
    <telerik:GridViewColumn Header="Club Name" Tag="False"/>
    <telerik:GridViewColumn Header="Established" Tag="False"/>
    <telerik:GridViewColumn Header="Capacity" Tag="False"/>
</telerik:RadGridView.Columns>

With that said, I hope the provided approaches work for your current project scenario.

Regards,
Stenly
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.

Arthur
Top achievements
Rank 1
Iron
Iron
Iron
commented on 01 Dec 2021, 09:24 AM | edited

Hello Stenly,

Thanks for your answer. You're right, I can't use the first approach you proposed, because I already have a specific hierarchy of classes, and creating a new class inheriting from GridViewColumn just for the sake of this flag seems unreasonable.

I didn't know about the Tag property, that's useful but not very maintainable in my opinion.
Is this new flag "IsRemovable" a new feature that could be considered by Telerik for a next update?
From my perspective, it doesn't look complicated to implement, nor irrelevant.
Thanks for your answer!

Arthur

Stenly
Telerik team
commented on 03 Dec 2021, 12:01 PM

Hello Arthur,

The wanted behavior is tied to the business logic of the application and it should be handled via custom logic. Adding an additional bool property (IsRemovable) to the GridView columns won't bring value to the control as it will only be an additional flag that can be used for anything in the application's logic. This is also the purpose of the Tag property in WPF. Additionally, the same effect can be achieved by extending the GridViewColumn class. 

Tags
GridView
Asked by
Arthur
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or