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

[Solved] Build RadDataGrid in C#

1 Answer 123 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brandon Peterson
Top achievements
Rank 2
Brandon Peterson asked on 26 Apr 2013, 01:30 AM
Is there a sample c# code behind to dynamically build the xaml grid below? I'm displaying a list of messages in a grid with multiple of these grids in a horizontal grid view style and the number of grids will be dynamic.

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled">
                <GridView HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" BorderThickness="2">
                    
                    <telerikGrid:RadDataGrid x:Name="DataGrid1" GridLinesVisibility="Horizontal" AlternateRowBackground="CornflowerBlue" GridLinesThickness="3">
                        <telerikGrid:RadDataGrid.Columns>
                            <telerikGrid:DataGridTemplateColumn Header="Country">
                                <telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Vertical">
                                            <TextBlock Text="{Binding CountryName}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                            <HyperlinkButton Content="Some link"></HyperlinkButton>
                                            <Button Content="Button"></Button>
                                        </StackPanel>
                                    </DataTemplate>
                                </telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                            </telerikGrid:DataGridTemplateColumn>

                        </telerikGrid:RadDataGrid.Columns>
                    </telerikGrid:RadDataGrid>

                    <telerikGrid:RadDataGrid x:Name="DataGrid2">
                        <telerikGrid:RadDataGrid.Columns>
                            <telerikGrid:DataGridTextColumn PropertyName="CapitalName" Header="Capital Name">
                                <telerikGrid:DataGridTextColumn.HeaderStyle>
                                    <Style TargetType="gridPrimitives:DataGridColumnHeader">
                                        <Setter Property="FontStyle" Value="Italic"/>
                                        <Setter Property="FontSize" Value="16"/>
                                    </Style>
                                </telerikGrid:DataGridTextColumn.HeaderStyle>
                            </telerikGrid:DataGridTextColumn>
                        </telerikGrid:RadDataGrid.Columns>
                    </telerikGrid:RadDataGrid>
</GridView>
            </ScrollViewer>

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 29 Apr 2013, 04:45 PM
Hello Brandon,

Thank you for using our RadControls for Windows 8!

You can create a RadDataGrid dynamically like this:
RadDataGrid DataGrid2 = new RadDataGrid();
DataGrid2.AutoGenerateColumns = false;
DataGridTextColumn textColumn = new DataGridTextColumn() { PropertyName = "CapitalName", Header = "Capital Name" };
textColumn.HeaderStyle = this.Resources["ColumnHeaderStyle"] as Style;
DataGrid2.Columns.Add(textColumn);
this.GridView.Items.Add(DataGrid2);

Where the ColumnHeaderStyle is defined in the resourses:
<Page.Resources>
      <Style TargetType="gridPrimitives:DataGridColumnHeader" x:Key="ColumnHeaderStyle">
              <Setter Property="FontStyle" Value="Italic"/>
              <Setter Property="FontSize" Value="16"/>
      </Style>
  </Page.Resources>

I hope this helps.

 

Kind regards,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Grid for XAML
Asked by
Brandon Peterson
Top achievements
Rank 2
Answers by
Ivaylo Gergov
Telerik team
Share this question
or