WPF Datagrid绑定和列显示 [英] WPF Datagrid binding and column display

查看:66
本文介绍了WPF Datagrid绑定和列显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据表作为DataGrid的项源,此数据表有很多列.不用创建新表就可以显示几列而不是全部列吗?

I have datatable as Item source for DataGrid, this datatable has lots of columns. Is it possible to display few columns instead all of them without creating a new table?

推荐答案

是的.只需标记 AutoGenerateColumns = False 并手动定义您的列即可.您可以使用普通的文本绑定列,复选框列,自定义XAML模板列等,如您在文档.

Yes, it is. Just mark AutoGenerateColumns=False and manually define your columns. You can use normal text-bound columns, checkbox columns, custom XAML template columns and more, as you can see in the documentation.

<DataGrid ItemsSource="{Binding DataSource}" AutoGenerateColumns="False" >
    <DataGrid.Columns>
    <DataGridTextColumn Header="Simple Value"
                      Binding="{Binding SimpleValue}" Width="*" />
     <DataGridTemplateColumn Width="*" Header="Complex Value">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <StackPanel>
               <TextBox Text="{Binding ComplexValue}"/>
               <TextBox Text="{Binding ComplexValue2}"/>
            </StackPanel>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
    </DataGrid.Columns>
  </DataGrid>

这篇关于WPF Datagrid绑定和列显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆