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

Empty ItemsSource based on ICustomTypeDescriptor when loaded

2 Answers 85 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Iron
Thomas asked on 02 Oct 2018, 12:03 PM

There seems to be a problem with the column creation, when the ItemsSource is empty when the GridView is loaded.

My scenario is simlar to the xaml-sdk-master\GridView\BindingToICustomTypeDescriptor sample. But it can happen, that the ItemsSource contains no items, when the grid is loaded. When the items arrive later, the columns are not build up correctly.

- When AutoGenerateColumns is used, no columns will appear.

- When I create the columns in code (AutoGenerateColumns is set to false and GridViewDataColumns are created and added before the grid is loaded) the columns are shown and the data is displayed, but I am not able to sort or filter the data.

Only when at least one item exits in the ItemsSource when the Grid becomes visible, the grid works as expected. Is there something I have to do, when the first item is available?

2 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
Iron
answered on 02 Oct 2018, 01:42 PM

Found a workaround:

  1. Check in OnLoaded if the ItemsSource has at least one item. If not:
  2. Subscribe the CollectionChanged event of the ItemsSource
  3. When the first item arrives, set the ItemsSource to null and back to the original value.
private static void RefreshColumns(DataControl gridView)
{
  object itemSource = gridView.ItemsSource;
  gridView.ItemsSource = null;
  gridView.ItemsSource = itemSource;
}

 

0
Martin Ivanov
Telerik team
answered on 04 Oct 2018, 06:50 AM
Hello Thomans

It is nice to hear that you found a resolution for your scenario. Also, thank you for sharing it here. I hope this is going to help someone else too.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Iron
Answers by
Thomas
Top achievements
Rank 1
Iron
Martin Ivanov
Telerik team
Share this question
or