This is a migrated thread and some comments may be shown as answers.
Visibility of grid inside grid
2 Answers 12 Views
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 14 Aug 2012, 11:38 PM
Hi,

I am in a scenratio where I have grid inside grid (HierarchyChildTemplate). Not all rows in outer grid have children records, so inside grid is visible for rows that do. I allow user to add/remove/edit children data.

Lets say that I have Groups and Products

Group A
Group B
    Product A
    Product B
GroupC
GroupD
    Product C
    Product D

AS it can be seen, ProductA and B belong to GroupB, and ProductC and D belong to GroupD. GroupA and GroupC don't have products in them.

1) If I click on some button, which executes a command on ViewModel, and some product is added to GroupA, RadGridView will not automatically display children records. In order for new product ProductE to appear under GroupA, I needed to execute below code each time a new product is added:

groupGrid.ItemContainerGenerator.ContainerFromItem(groupGrid.SelectedItem) as GridViewRow;
 
if (row != null)
{
    row.IsExpandable = true;
    row.IsExpanded = true;
}

Is this the correct way to do this, and why the grid doesn't sense the notifications from ObservableCollection of Products?

2) If I remove ProductC and ProductD, then GroupD should hidechild grid. However, if at this point I insert a new product inside GroupD, child grid should appear again. I am having difficulties in implementing this requirement. If I bind to Visibility, I could solve the problem with inserting / removing products, since I am ading/removing in ViewModel, I just need to set value for ProductsExist in AddProduct/RemoveProduct commands.

Visibility="{Binding ProductsExist, Source={StaticResource viewModel}, Converter={StaticResource boolToVisibilityConverter}}"

However, the problem appears during data loading, Since this is asyncronous process, I would need to set some flags to know when loading is finished, so I can correct the value for ProductsExist.

I am finding all this a bit dirty. What are your suggestions to solve this problems of appearance with inside grid? And why is this not automatic, if child grid is bound to ObservableCollection<Product>? It can pick up notifications from INCC and react accordingly.

Regards,
Goran

2 Answers, 1 is accepted

Sort by
0
Goran
Top achievements
Rank 1
answered on 14 Aug 2012, 11:48 PM
in addition to second point, setting the flag will not have proper results, since templates are recreated after the data is fetched, so IsLoading flag will always be false.
0
Dimitrina
Telerik team
answered on 20 Aug 2012, 07:54 AM
Hi Goran,

Indeed, the GridViewRows does not listen for such notifications and they cannot automatically update their state. This is done by design.

When you manually update the IsExpanded/IsExpandable states you should be able to achieve a consistent state of showing the expand/collapse state. This is a correct way.

I am not sure what exactly do you do with approach two. If approach 1 works for you, please use it.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Asked by
Goran
Top achievements
Rank 1
Answers by
Goran
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or