如何在只读数据网格中编辑一列?
<DataGrid x:Name="dgLoadDtl" Height="315" Width="710" Grid.Row="0"
HorizontalAlignment="Left" VerticalAlignment="Bottom"
Style="{DynamicResource StyleDatagrid}"
IsReadOnly="true">
<DataGrid.Columns>
<DataGridTextColumn Foreground="Black" Width="60" Header="Sctn" Binding="{Binding Sctn, Mode=TwoWay}" IsReadOnly="false" />
<DataGridTextColumn Foreground="Black" Width="140" Header="CustName" Binding="{Binding CustName, Mode=TwoWay}" />
<DataGridTextColumn Foreground="Black" Width="140" Header="Address" Binding="{Binding Address1, Mode=TwoWay}" />
<DataGridTextColumn Foreground="Black" Width="50" Header="Bulk or Bag" Binding="{Binding BulkorBag, Mode=TwoWay}" />
<DataGridTextColumn Foreground="Black" Width="80" Header="ProdCode" Binding="{Binding ProdCode, Mode=TwoWay}" />
<DataGridTextColumn Foreground="Black" Width="80" Header="MedCode" Binding="{Binding MedCode, Mode=TwoWay}" />
答案 0 :(得分:12)
我创建了一个示例,我将DataGrid的ItemsSource绑定到ObservableCollection,从这里你有两个选项。
以下是选项1的示例代码:
<DataGrid x:Name="dgLoadDtl" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{Binding MyData}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Foreground="Black" Width="60" Header="Sctn" Binding="{Binding Sctn, Mode=TwoWay}" IsReadOnly="false" />
<DataGridTextColumn Foreground="Black" Width="140" Header="CustName" Binding="{Binding CustName, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn Foreground="Black" Width="140" Header="Address" Binding="{Binding Address1, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn Foreground="Black" Width="50" Header="Bulk or Bag" Binding="{Binding BulkorBag, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn Foreground="Black" Width="80" Header="ProdCode" Binding="{Binding ProdCode, Mode=TwoWay}" IsReadOnly="True"/>
<DataGridTextColumn Foreground="Black" Width="80" Header="MedCode" Binding="{Binding MedCode, Mode=TwoWay}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>