我需要在我的数据网格中添加行标题,我正在使用数据表,绑定如下:
dg1.ItemsSource = Data.DefaultView;
现在,我该如何添加行标题?这是我的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>
答案 0 :(得分:-1)
如何添加行:
DataGridName.Items.Add(new DataItem());
如何添加列:
DataGridTextColumn column = new DataGridTextColumn();
column.Header = "Column 1";
column.Binding = new Binding("Column1");
dataGridName.Columns.Add(column);