I need to add row header to my datagrid,I'm using a datatable, binding like this:
dg1.ItemsSource = Data.DefaultView;
Now, how can I add row header? this is my xaml:
<DataGrid Name="dg1"
MinColumnWidth="19" MinRowHeight="19"
ItemsSource="{Binding Data.DefaultView}"
FontFamily="B Nazanin" FontSize="14"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False"
HorizontalContentAlignment="Stretch"
HorizontalAlignment="Left"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Height="58" Margin="13,82,0,-83" Width="532"
UseLayoutRounding="False" IsReadOnly="True" LoadingRow="dg1_LoadingRow"
>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="FontSize" Value="15"/>
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
How to add a row:
DataGridName.Items.Add(new DataItem());
How to add a column:
DataGridTextColumn column = new DataGridTextColumn();
column.Header = "Column 1";
column.Binding = new Binding("Column1");
dataGridName.Columns.Add(column);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.