Articles in this section
Category / Section

How to add multiple views in a grid cell in DataGrid?

2 mins read

You can add multiple views in a grid cell in SfDataGrid using the GridTemplateColumn. You can load any number of views in GridCell by customizing the CellTemplate property of the GridTemplateColumn.

The below code illustrates how to add multiple views in a grid cell by customizing the CellTemplate property of a GridTemplateColumn.

<ContentPage.Content>
  <syncfusion:SfDataGrid x:Name="dataGrid"
                      AutoGenerateColumns="False"
                      ColumnSizer="Star"
                      ItemsSource="{Binding OrdersInfo}"
                      RowHeight="180">
    <syncfusion:SfDataGrid.Columns>
      <syncfusion:GridTemplateColumn HeaderText="Orders Information" MappingName="OrderID">
        <syncfusion:GridTemplateColumn.CellTemplate>
          <DataTemplate>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="100" />
              </Grid.ColumnDefinitions>
              <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
                <RowDefinition Height="40" />
              </Grid.RowDefinitions>
              <Label Grid.Row="0"
                      Grid.Column="0"
                      FontAttributes="Bold"
                      HorizontalTextAlignment="Center"
                      Text="OrderID"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="0"
                      Grid.Column="1"
                      HorizontalTextAlignment="Center"
                      Text=":"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="0"
                      Grid.Column="2"
                      HorizontalTextAlignment="Center"
                      Text="{Binding OrderID}"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="1"
                      Grid.Column="0"
                      FontAttributes="Bold"
                      HorizontalTextAlignment="Center"
                      Text="CustomerID"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="1"
                      Grid.Column="1"
                      HorizontalTextAlignment="Center"
                      Text=":"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="1"
                      Grid.Column="2"
                      HorizontalTextAlignment="Center"
                      Text="{Binding CustomerID}"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="2"
                      Grid.Column="0"
                      FontAttributes="Bold"
                      HorizontalTextAlignment="Center"
                      Text="Freight"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="2"
                      Grid.Column="1"
                      HorizontalTextAlignment="Center"
                      Text=":"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="2"
                      Grid.Column="2"
                      HorizontalTextAlignment="Center"
                      Text="{Binding Freight}"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="3"
                      Grid.Column="0"
                      FontAttributes="Bold"
                      HorizontalTextAlignment="Center"
                      Text="Country"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="3"
                      Grid.Column="1"
                      HorizontalTextAlignment="Center"
                      Text=":"
                      TextColor="Black"
                      VerticalTextAlignment="Center" />
              <Label Grid.Row="3"
                      Grid.Column="2"
                      HorizontalTextAlignment="Center"
                      Text="{Binding Country}"
                      VerticalTextAlignment="Center" />
            </Grid>
          </DataTemplate>
        </syncfusion:GridTemplateColumn.CellTemplate>
      </syncfusion:GridTemplateColumn>
    </syncfusion:SfDataGrid.Columns>
  </syncfusion:SfDataGrid>
</ContentPage.Content>

 

 

On executing the above code the below output is obtained.

Order Information

 

Sample Link:

How to add multi-line texts in SfDataGrid grid cells?


Conclusion

I hope you enjoyed learning about how to add multiple views in a grid cell in DataGrid.

You can refer to our  Xamarin.Forms DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our  Xamarin.Forms DataGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied