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

Binding GridView in DataTemplate

4 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jean michel
Top achievements
Rank 1
jean michel asked on 28 Jul 2010, 02:49 PM
Hello,

I don't obtain binding my subGridView in DataTemplate.

In grid main I fill with a list and in subGrid I have that to fill with another list.

How I make to fill mine subGrid with another list?

My project is SL3

It follows below:

<Grid x:Name="LayoutRoot">
        <!-- Grid Principal-->
        <grid:RadGridView x:Name="GridViewEstruturaPessoa"
                          RowIndicatorVisibility="Collapsed"
                          ShowColumnHeaders="False"
                          ShowGroupPanel="False"    
                          ShowColumnFooters="False"
                          ShowGroupFooters="False"
                          GridLinesVisibility="None"
                          Width="670"
                          SelectionMode="Multiple"
                          BorderBrush="#CFCFCF"
                          BorderThickness="1"
                          IsReadOnly="True"
                          AutoGenerateColumns="False"
                          CanUserFreezeColumns="False"
                          CanUserReorderColumns="False"
                          CanUserResizeColumns="False"
                          CanUserSortColumns="True"
                          IsFilteringAllowed="True"
                          ColumnWidth="*"
                          AlternationCount="2"
                          AlternateRowBackground="#EFEFEF"
                          >
            <grid:RadGridView.HeaderRowStyle>
                <Style TargetType="gridView:GridViewHeaderRow">
                    <Setter Property="Background" Value="Transparent" />
                </Style>
            </grid:RadGridView.HeaderRowStyle>
            <grid:RadGridView.Columns>
                <grid:GridViewToggleRowDetailsColumn />
                <grid:GridViewImageColumn Header="Imagem" HeaderCellStyle="{StaticResource MyHeaderCellStyle}"  DataMemberBinding="{Binding Imagem}" Width="25" />
                <grid:GridViewDataColumn Header="Nome" HeaderCellStyle="{StaticResource MyHeaderCellStyle}"  DataMemberBinding="{Binding Descricao}" />
            </grid:RadGridView.Columns>
            <grid:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <!-- Sub Grid de Funcionarios-->
                    <grid:RadGridView
                          RowIndicatorVisibility="Collapsed"
                          SelectionMode="Multiple"
                          Width="650"
                          BorderBrush="#CFCFCF"
                          BorderThickness="1"
                          IsReadOnly="True"
                          AutoGenerateColumns="False"
                          ShowGroupPanel="False"    
                          CanUserFreezeColumns="False"
                          CanUserReorderColumns="False"
                          CanUserResizeColumns="False"
                          CanUserSortColumns="True"
                          IsFilteringAllowed="True"
                          ColumnWidth="*"
                          AlternationCount="2"
                          AlternateRowBackground="#EFEFEF"
                          >
                        <grid:RadGridView.HeaderRowStyle>
                            <Style TargetType="gridView:GridViewHeaderRow">
                                <Setter Property="Background" Value="Transparent" />
                            </Style>
                        </grid:RadGridView.HeaderRowStyle>
                        <grid:RadGridView.Columns>
                            <grid:GridViewDataColumn Header="Nome" HeaderCellStyle="{StaticResource MyHeaderCellStyle}"  DataMemberBinding="{Binding Descricao}" />
                        </grid:RadGridView.Columns>
                    </grid:RadGridView>
                </DataTemplate>
            </grid:RadGridView.RowDetailsTemplate>
        </grid:RadGridView>
    </Grid>

public partial class GridEstruturaPessoa : UserControl
{
    ObservableCollection<IHierarquico> lEstruturaPessoa = new ObservableCollection<IHierarquico>();
    ObservableCollection<RecFuncionarioCadastro> lFuncionario = new ObservableCollection<RecFuncionarioCadastro>();
    public GridEstruturaPessoa()
    {
        InitializeComponent();
        foreach (DtoHierarquiaPessoa item in lFuncionario)
        {
            lEstruturaPessoa = ctrEstruturaHierarquicaPessoa.RetornaHierarquiaPessoa().Where(t => t is DtoHierarquiaEstrutura).Cast<DtoHierarquiaEstrutura>()
                                                                                                    .FirstOrDefault(c => c != null && c.Id.Equals(item.Estrutura.IdSource));
        }
        GridViewEstruturaPessoa.ItemsSource = lEstruturaPessoa;
    }



4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 28 Jul 2010, 03:06 PM
Hi,

 You can use Loaded event of the child grid for example to fill the child grid will data or you can use MVVM similar to this blog post for example. 

Best wishes,
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
jean michel
Top achievements
Rank 1
answered on 29 Jul 2010, 03:49 PM
Hello Vlad,

In execution time as I can create a datatemplate in the event RowDetailsVisibilityChanged?

Thanks!
0
Vlad
Telerik team
answered on 04 Aug 2010, 07:23 AM
Hi,

 Indeed you can do this. Here is an example:

private void grdPeople_RowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
        {
            e.Row.DetailsTemplate = (DataTemplate)this.Resources["MyTemplate"];
        }

Best wishes,
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
jean michel
Top achievements
Rank 1
answered on 04 Aug 2010, 03:05 PM
Hello Vlad,

Which the error of my DataTemplate in my XAML?

<grid:RadGridView.RowDetailsTemplate x:Key="MyTemplate">
           <DataTemplate>
               <App:SubGridEstruturaPessoaTeste></App:SubGridEstruturaPessoaTeste>
           </DataTemplate>
</grid:RadGridView.RowDetailsTemplate>

Thanks!!!

Tags
GridView
Asked by
jean michel
Top achievements
Rank 1
Answers by
Vlad
Telerik team
jean michel
Top achievements
Rank 1
Share this question
or