RadGridView and BindingToICustomTypeDescriptor with ListCollectionView

1 Answer 96 Views
GridView
Guarana91
Top achievements
Rank 1
Iron
Iron
Guarana91 asked on 12 Sep 2022, 11:46 AM

Hello,

is it possible to use a ListCollectionView for BindingToICustomTypeDescriptor in a RadGridView?

If yes how?

I attached the project from Telerik and tryed it out with an ListCollectionView but the data will not show properly.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 15 Sep 2022, 09:50 AM

Hello,

In this particular case the ListCollectionView is actually bound correctly, but the control cannot generate the columns automatically due to the nature of the bound data.

You can, however, manually define the columns either in XAML or you can use the approach demonstrated in the Binding Columns From ViewModel to generate the columns in the ViewModel and bind them. I've gone ahead and implemented the first approach in the sample project you provided.

Please give this a try and let me know if any of these approaches would work for you.

Guarana91
Top achievements
Rank 1
Iron
Iron
commented on 13 Oct 2022, 09:39 AM

Hello Dikyan and sorry for the late answer,

manually define the columns is unfortunately not an option. I need the columns be auto genrated like the example with the observableCollection.

I will look at your example with Binding Columns from ViewModel :-)

Dilyan Traykov
Telerik team
commented on 14 Oct 2022, 12:54 PM

Do let me know if binding to the Columns collection via a custom behavior works for you.
Guarana91
Top achievements
Rank 1
Iron
Iron
commented on 17 Oct 2022, 12:25 PM

The example with Binding Columns from ViewModel is unfortunately not good. If there is no way to use a ListCollectionView, I have to use a ObservableCollection. I think the problem is in the PropertyDescriptor class.
Dilyan Traykov
Telerik team
commented on 19 Oct 2022, 12:53 PM

An alternative approach I can suggest would be to handle the DataLoaded event of the control as follows to automatically generate the columns:

        private void GridView_DataLoaded(object sender, System.EventArgs e)
        {
            if (this.GridView.Columns.Count == 0)
            {
                var customTypeDescriptor = this.GridView.Items[0] as ICustomTypeDescriptor;
                foreach (MyPropertyDescriptor prop in customTypeDescriptor.GetProperties())
                {
                    this.GridView.Columns.Add(new GridViewDataColumn()
                    {
                        DataMemberBinding = new Binding(prop.Name),
                        Header = prop.Name
                    });
                }
            }
        }

Can you please give this a try and let me know if this would work for you? If that is not the case, please specify why the approach suggested in the "Binding Columns from ViewModel" demo would not work for you so that I can try to suggest a viable solution.

Guarana91
Top achievements
Rank 1
Iron
Iron
commented on 21 Oct 2022, 11:41 AM

Thanks Dilyan,

its working now with the DataLoad event :-)

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