简体   繁体   English

wpf / c#:创建一个部分只读和部分可编辑的数据网格

[英]wpf/c#: creating a datagrid which is partly read-only and partly editable

I want to create a DataGrid of four rows (fixed) and a variable number of columns (between six and ten). 我想创建一个四行(固定)和可变列数(六到十之间)的DataGrid。 Two of the rows need to be editable in all columns, the remaining two need to be read-only except for one column (differentiated by the value of a variable) which needs to be editable on all rows. 其中的两行必须在所有列中都是可编辑的,其余两行必须是只读的, 除了需要在所有行中都可编辑的一列(由变量的值区分)。 I can make this column editable while the rest of the DataGrid is read-only easily enough, but this problem is more complex than that. 我可以使此列可编辑,而DataGrid的其余部分很容易只读,但是这个问题比这更复杂。 I'm fairly new to WPF so any answers involving XAML code need to be explained so that a novice can understand! 我是WPF的新手,因此需要解释任何涉及XAML代码的答案,以便新手可以理解!

Set IsReadOnly True or False for each column individually 为每个列分别设置IsReadOnly TrueFalse

Edit: but this would not work for each Row individually, in which case it would give a little more work, this question/answer will help you 编辑:但这不适用于每个行,在这种情况下,它会给您带来更多工作, 此问题/答案将为您提供帮助

<DataGrid ColumnWidth="*" 
          AutoGenerateColumns="False" 
          SelectionMode="Single" 
          HorizontalContentAlignment="Center" 
          ItemsSource="{Binding DataGridItems}" 
          ScrollViewer.CanContentScroll="True" 
          ScrollViewer.VerticalScrollBarVisibility="Auto" 
          ScrollViewer.HorizontalScrollBarVisibility="Auto" >
    <DataGrid.Columns>
        <DataGridTextColumn .... IsReadOnly="True"/>
        <DataGridTextColumn .... IsReadOnly="True"/>
        <DataGridTextColumn .... IsReadOnly="False"/>
    </DataGrid.Columns>
</DataGrid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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