Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit dataGrid RowDetails with several lines
5 replies. Latest Post by yifung on July 13, 2009.
(0)
prl
Member
7 points
45 Posts
06-29-2009 10:40 AM |
Hello,
Is this possible? To have several rows on a the RowDetails? I have a datagrid and I want to group several items below a certain row. I tried inserting a DataGrid in the row details but then in the .cs code I could access it to set the ItemsSource.
I have the following code:
<data:DataGrid x:Name="taxaPenDetails" Background="Transparent" Margin="30,47,30,65" AutoGenerateColumns="False"> <data:DataGrid.RowDetailsTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Background="Beige"> <data:DataGrid x:Name="innerGrid"> (...) </data:DataGrid> </StackPanel> </DataTemplate> </data:DataGrid.RowDetailsTemplate> <data:DataGrid.Columns> (...) </data:DataGrid>
Thanks.
yifung
Contributor
3257 points
537 Posts
06-29-2009 5:30 PM |
You could put a DataGrid in the RowDetails of another DataGrid. If you do so, you should DataBind the inner DataGrid's ItemsSource to a collection on your entity.
However, instead of doing that for this scenario, you should take advantage of the new RowGrouping feature that's part of the Silverlight 3 DataGrid.
06-29-2009 7:03 PM |
I put a DataGrid in the RowDetails of the other DataGrid but in the code behind I can't access it to set its Items Source. I thought the inner DataGrid would inherit the outer DataGrid's ItemsSource but apparently it doesn't :\ Is there any other solution or am I doing anything wrong?
I can't use Silverlight 3 just yet. Gotta wait until it's released..
06-29-2009 7:10 PM |
The DataContext for the RowDetails is the same as the DataContext of the Row that the details belongs to. That happens to be the Item that the row represents so you would need a collection on your item for that to work right. If you can't DataBind, you could listen to the LoadingRowDetails event and set the ItemsSource there. If you do so you'd have to be sure to set it each time because the rows including their details are reused for other data.
07-01-2009 10:14 AM |
Thanks for your answer, I'm still trying to do this.
I have another question. Is it possible to have a row not have RowDetails? My datagrid has its data bound from an external source (silverlight-enabled wcf service) and all the rows have the rowdetails (even when there's no data to show inside). Can I have a specific row to not have these details?
Cheers
07-13-2009 1:58 PM |
You could bind the Visibility of what's in your row details template to something appropriate to have rows that have and don't have details. You might need to use a ValueConverter as part of the Binding so you can Convert from say an empty collection to Visibility.Collapsed.