简体   繁体   中英

WPF DataGrid Binding properties

I have an ItemSource that is bounded to a DataGrid. However, all of the properties of the ItemSource is being shown in the grid, but I have only specified a few columns (properties) that I want the user to see and modify in the XAML

<DataGrid.Columns>
       .. Column 1...
       .. Column 2...
</DataGrid.Columns>

I am guessing there is a property of the grid that I will need to set to false so it only shows the columns or properties that I have personally specified.

If not, any ideas of how I can achieve this?

Thanks

Set AutoGenerateColumns=False on dataGrid and provide your own set of columns under Columns tag.

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding SourceCollection}">
  <DataGrid.Columns>
    <DataGridTextColumn Header="Id" Binding="{Binding Id}"/>
    <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
  </DataGrid.Columns>
</DataGrid>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM