This is a migrated thread and some comments may be shown as answers.

Getting Item Type from GridView

2 Answers 208 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Veteran
David asked on 13 Nov 2020, 04:35 PM

Hi

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

Sort by
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));

                }

                return this.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/.

0
David
Top achievements
Rank 1
Veteran
answered on 19 Nov 2020, 10:21 AM

Thanks, Dilyan.

 

That works perfectly!

 

Regards

Dave

 

 

Tags
GridView
Asked by
David
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
David
Top achievements
Rank 1
Veteran
Share this question
or