【发布时间】:2016-06-24 07:15:26
【问题描述】:
我需要使我的 DataGrid 列可编辑,但不知道如何做到这一点。 当我尝试编辑列时,我发现异常“此视图不允许 EditItem”。
我的 XAML:
<DataGrid IsReadOnly="False" AutoGenerateColumns="False" Margin="6,6,5,18" Name="dataGrid1" ItemsSource="{Binding MyDictionary}" CellEditEnding="dataGrid1_editCells">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Header="Name" Binding="{Binding Key}" />
<DataGridTextColumn IsReadOnly="False" Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
还有.cs:
public partial class MyView : Window
{
private Dictionary<string, string> myDictionary = new Dictionary<string, string>();
public Dictionary<string, string> Dictionary { get { return myDictionary ; } set { myDictionary = value; } }
public MyView()
{
// Here is some code that fills dictionary
InitializeComponent();
this.DataContext = this;
}
}
有什么问题?如何使我的第二列可编辑?
【问题讨论】:
-
为什么不使用 observablecollection?