我需要使我的DataGrid列可編輯,但無法弄清楚如何做到這一點。 當我嘗試編輯列時,我發現異常「EditItem不允許用於此視圖」。使WPF DataGrid列可編輯
我的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? – riteshmeher