如何更改列中的单元格(在datagrid中)

时间:2011-07-30 20:57:58

标签: wpfdatagrid

xaml:

 <dg:DataGrid AutoGenerateColumns="False" Background="#FF484040" BorderBrush="#FF484040" CanUserAddRows="False" CanUserDeleteRows="False" Grid.ColumnSpan="2" HeadersVisibility="Column" Height="195" IsReadOnly="True" Margin="21,12,52,105" Name="dataGrid" SelectedIndex="-1" Width="399">
            <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Binding="{Binding IdBook}" Header=" IdBook" ></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding NameBook}" Header="NameBook"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding Author}" Header="Author"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding Price}" Header="Price"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding DateRegister}" Header="DateRegister"></dg:DataGridTextColumn>
            <dg:DataGridTextColumn Binding="{Binding Description}" Header="Description" Width="*"></dg:DataGridTextColumn>
            <dg:DataGridTemplateColumn>

                <dg:DataGridTemplateColumn Width="15">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox Height="15" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Name="Checkbox" ToolTip="select" VerticalAlignment="Center" VerticalContentAlignment="Center" Width="15" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
            </dg:DataGrid.Columns>
        </dg:DataGrid>

如何更改第7列中的单元格

1 个答案:

答案 0 :(得分:0)

您将获得数据源中的列数。您可以使用以下命令获取网格中的列数:

MessageBox.Show(dataGrid.Columns.Count.ToString());