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

[Solved] Get Row Item in RowDetail

3 Answers 141 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.
invDev
Top achievements
Rank 1
invDev asked on 10 Feb 2011, 01:51 PM
Hey,

i'm just wondering if it is possible to get the data object which represents a single row in the row detail. Im using a RowDetailsTemplate with just a custom UserControl like this:

<DataTemplate x:Key="myDataTemplate">
    <myControls:MyUserControl></myControls:MyUserControl>
</DataTemplate>

If the detail view opens, I get a proper instance of the MyUserControl class. Can I access the original row data from e.g. the constructor?

Thanks for your help!

Jonas

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 10 Feb 2011, 01:59 PM
Hi Jonas,

 The DataContext of the UserControl is the data object itself. 

Greetings,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
invDev
Top achievements
Rank 1
answered on 10 Feb 2011, 02:14 PM
That was my first attempt, but sadly the DataContext property is null.

I bind the template like this: 

this.myGrid.RowDetailsTemplate = App.Current.Resources["myDataTemplate"] as DataTemplate;

The template is definded in the App.xaml
0
Accepted
Rossen Hristov
Telerik team
answered on 10 Feb 2011, 02:41 PM
Hello invDev,

It does not matter where the Row Details Template is detailed. When the row details show up, the respective data item becomes the DataContext of the whole thing that is inside the row details.

You cannot access it from the constructor because the order of events is the following:

1. The user requests to see the row details for row X.
2. Our code reads the DataTemplate which you have defined and performs a Load, i.e. it instantiates the UserControl you have defined. The UserControl is now alive.
3. The respective data item of the row is assigned as the DataContext for this user control. So if your business object has a property called "PropA", you can Data Bind something on your User Control to this PropA.
4. The Visibility of the row details is set to Visible and the user sees them.

So you can attach to the LoadingRowDetails event and in the event handler you will have access to the row so you can get the data item and pass in in some way to user control. Alternatively you can cast the DataContext of the user controls to respective type. They are the same thing -- i.e. the data item of the row and the DataContext of the user control point to the same thing -- the data item of the row.

I hope this helps. Let me know if you have any other questions.

Best wishes,
Ross
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
invDev
Top achievements
Rank 1
Answers by
Vlad
Telerik team
invDev
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or