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

Hide entire gridView when empty

3 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Björn Metzinger
Top achievements
Rank 1
Björn Metzinger asked on 09 Apr 2010, 10:14 AM
Hello

What is the recommended way to hide a data-bound (ObservableCollection) gridView entirely when it has no items to be displayed? I want to avoid the effect of only having a grid header, but no data rows below it.

With Q1-2010, I'm using this code:

gridView.Visibility = (gridView.Items.Count > 0) ? Visibility.Visible : Visibility.Collapsed;

but I don't know when (i.e. in which event handler) one has to call it. I tried the "DataLoaded" event, but this one does not seem to fire when no data at all is in the grid. And "DataLoading" seems not to fire at all (what is this for???). And the inherited "Loaded" event seems to be the wrong time, because the information what data will be in the gridView is not present at this time.

Any hints?

Regards,
Björn

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Apr 2010, 11:44 AM
Hi Björn,

Why not use MVVM to handle this? You can check the attached example application for reference.

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Björn Metzinger
Top achievements
Rank 1
answered on 09 Apr 2010, 02:30 PM
Thank you, Vlad! That solution is not directly applicable in my case; however it proved helpful to get it working as expected.

There is just one little issue left: when using data-binding with the converter, as you recommended, then sometimes the columns "lose" their initially given width ("Star"), so that they become very narrow, sticking all on the left border of the gridview, instead of stretching along its entire width (in Q1-2010 official release). See attached screenshots.

Is there a way to prevent this incorrect behavior? Re-setting the column width on the visibility changed event doesn't help here.

Thanks
Björn


0
Vlad
Telerik team
answered on 09 Apr 2010, 02:46 PM
Hello Björn,

I've tried to reproduce this incorrect behavior however the grid worked as expected on my end. Please check the attached application.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Björn Metzinger
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Björn Metzinger
Top achievements
Rank 1
Share this question
or