Is there a simple way to obtain the Item Type of the items in the source collection of RadGridView?
I see that there is an Items.ItemType property, but this always seems to be null.
Thanks for any help.
Kind regards
Dave
2 Answers, 1 is accepted
0
Accepted
Dilyan Traykov
Telerik team
answered on 18 Nov 2020, 12:33 PM
Hi Dave,
Indeed, the ItemType property is not actually set by the RadGridView control but is instead there to be defined by the developer if the type cannot be automatically inferred by its data engine and leads to issues with the data operations (such as sorting, filtering, and grouping) of the control.
What I can suggest is to use a QueryableCollectionView as the ItemsSource for the RadGridView control which also exposes a constructor to set the ItemType. For example:
private QueryableCollectionView data;
public QueryableCollectionView Data
{
get
{
if (this.data == null)
{
this.data = new QueryableCollectionView(new List<string>() { "one", "two" }, typeof(string));
}
returnthis.data;
}
}
You can then use the ItemType of this view to handle your custom logic:
var qcv = this.GridView.Items.SourceCollection as QueryableCollectionView;
var itemType = qcv.ItemType;
Please let me know whether such an approach would work for you.
Regards,
Dilyan Traykov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.