2011-07-30 70 views
0

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

回答

0

你得到的數據源中的列數。您可以使用get在網格中的列數:

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

不錯的答案............ – mrJack

+0

如何改變細胞的7列? – mrJack

+0

@mrJack:您在該列中沒有任何數據綁定,所以我不確定這是可能的。您應該添加數據綁定,然後您可以更改數據源中的值並更新網格。 – Guffa

相關問題