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

[Solved] Getting data source asynchronously for Child record in custom hierarchy GridView

10 Answers 337 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
D. Omar
Top achievements
Rank 1
D. Omar asked on 21 Jul 2009, 05:37 AM
I have an ID property on the items in the ItemsSource for the main grid and I have a HierarchyChildTemplate and I want to use that ID to get the data object to be used as source/DataContext for the Child row asynchronously (WCF service call) when the Expandable Row State changes to Expanded. Based on the examples I decided to first try the TableDefinition_PreviewDataRecordCreate event handler with hardcoded values (before trying the async approach) but the DataContext for the objects in the child row or HierarchyTemplate continues to be the Item from the top-level grid's ItemsSource. It is like if the detail/child row were just ignoring the ChildTableDefinition.DataSource.

What am I missing? What is the correct way of doing this?

Thanks in advance,

-OmarV

10 Answers, 1 is accepted

Sort by
0
D. Omar
Top achievements
Rank 1
answered on 21 Jul 2009, 03:51 PM
I forgot to mention: I am using the Q2/2009 bits.
0
Pavel Pavlov
Telerik team
answered on 23 Jul 2009, 04:24 PM

Hello D. Omar,
I may suggest the following approach :

Subscribe to ExpanderRowStateChangedEvent the following way:

this.AddHandler(GridViewExpandableRow.ExpanderRowStateChangedEvent, new RoutedEventHandler(OnExpanderRowStateChangedEvent), true); 

This event will fire after the user has pressed the expand button .
Within the event handler you may get acces to the expandableRow this way :

void OnExpanderRowStateChangedEvent(object sender, RoutedEventArgs args)  
        {  
            GridViewExpandableRow expandableRow = ((RadRoutedEventArgs) args).Source  
        } 

After you have got the reference to rhe expandableRow , you may  set its DataContext , manipulate contained controls. ( e.g. set explicitly datasource).

In case you have any troubles with that , just let me know. I will gladly prepare a sample for you .

All the best,

Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
D. Omar
Top achievements
Rank 1
answered on 23 Jul 2009, 04:41 PM
Thank you!

I am actually using the OnExpanderRowSTateChanged event, the difference is that I used 'sender' instead of 'args':

GridViewExpandableRow expandableRow = (GridViewExpandableRow)sender 

What is the difference?

But this does not solve my problem, I am using this event's handler to call the WCF service that is going to get me the data source for my details row, the DataContext for my user control in my HierarchyChildTemplate, which is going to come back asynchronously. Right now what I am doing is listening to the "Loaded" event of my HierarchyChildTemplate user control and storing a reference to it in a dictionary with my ID property as the key, then when the WCF service calls back, I use that dictionary to get the reference to my user control and set the data object. But this feels like a hack, what is the purpose of the GirdView Child Tables then if I cannot bind to them? Are those only useful if the Hierarchy Child Template has a GridView in it?

-OmarV



0
Pavel Pavlov
Telerik team
answered on 24 Jul 2009, 01:29 PM

Hi Omar,

As far as it works , your approach seems acceptable to me .

About the child table definitions - So far their main purpose is to support standard hierarchy and nod so complicated scenarios.

Since I found your request absolutely reasonable , i have talked to the team. We have decided to improve the hierarchy API in order to ease  the completion of scenarios like yours. This has been logged in our backlog and prioritized. This means it will appear in a future release of the RadGridView.

Thank you for the productive feedback. I have updated your Telerik points.

Kind regards,

Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
D. Omar
Top achievements
Rank 1
answered on 05 Aug 2009, 03:02 AM
I just realized there is a RowDetailsTemplate property on the GridView but the help is not clear about the difference between RowDetailsTemplate and HierarchyChildTemplate. After glancing at the samples, it looks like RowDetailsTemplate is a better fit for what I am trying to do. Can someone please validate this?

Thanks in advance,
0
Vlad
Telerik team
answered on 05 Aug 2009, 05:14 AM
Hi Omar,

Row Details is just another option and indeed can be used in such scenarios. If you want also expand/collapse column for Row Details similar to traditinal hierarchy please visit this blog post for more info:
http://blogs.telerik.com/blogs/posts/09-07-30/how_to_display_hierarchical_data_with_row_details_radgridview_for_silverlight.aspx

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
D. Omar
Top achievements
Rank 1
answered on 05 Aug 2009, 01:02 PM
Thank you! I don't know if I am going to have time to switch so just in case, is there a way to omit the expand/collapse column when using the HierarchyChildTemplate? Also, can you please explain what other differences exist between the two? Is there an equivalent to OnExpandedRowStateChanged event when using RowDetailsTemplate? Can I have full control of when the details for a particular row are shown? What I need in regards to that is for the RowDetailsVisibilityMode to be Collapsed and let the user select when to show it but also make sure that only one row shows the details at a time, similar to the VisibleWhenSelected behavior but actually letting the user decide when to show details.
0
Rossen Hristov
Telerik team
answered on 11 Aug 2009, 08:06 AM
Hi D. Omar,

The RowDetails equivalent of OnExpandedRowStateChanged is called RowDetailsVisibilityChanged. This event is fired when row details are shown or hidden.

You can have full control over each individual GridViewRow through its DetailsVisibility property. Actually, in my blog post the toggle button in the leftmost column uses this property to show / hide row details, but you can do it programmatically from anywhere since the DetailsVisibility property is public.

Changing this property will result in the above mentioned RowDetailsVisibilityChanged event being fired for the grid. In the EventArgs of the event you will have the GridViewRow for which the details have been shown or hidden. To check whether they were shown or hidden you can read the e.Row.DetailsProvider.DetailsVisibility property.

I have prepared a small skeleton project that demonstrates all of the above.

Have in mind that I am using the latest internal build and you will need to upgrade if you want to have the RowDetailsVisibilityChanged event.

Kind regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
D. Omar
Top achievements
Rank 1
answered on 11 Aug 2009, 09:10 AM
Is there a way to omit the expand/collapse column when using the HierarchyChildTemplate?
0
Rossen Hristov
Telerik team
answered on 14 Aug 2009, 07:34 AM
Hello D. Omar,

There is a way, but it is not very easy. You will have to redefine the GridViewExpandableRow template and remove the plus sign. To learn how to style a row with blend, please see this help topic. The topic is about GridViewRow and GridViewNewRow, but the general approach is the same for all elements. 

All the best,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
D. Omar
Top achievements
Rank 1
Answers by
D. Omar
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Vlad
Telerik team
Rossen Hristov
Telerik team
Share this question
or