Sunday, 18 August 2013

DataGrid can not be edit

DataGrid can not be edit

I want to use a DataGrid in my window to show and edit some lines of
string.Code as below:
public class StringWrapper
{
public string Value { get; set; }
}
DataGrid dgd = new DataGrid();
dgd.HorizontalAlignment = HorizontalAlignment.Left;
DataGridTextColumn textcolumn = new DataGridTextColumn();
textcolumn.Width = 150;
textcolumn.Header = "Value";
textcolumn.Binding = new Binding("Value");
dgd.Columns.Add(textcolumn);
foreach (var s in lststring)
{
dgd.Items.Add(new StringWrapper { Value = "test string" });
}
spanel.Children.Add(dgd);
Now I can show the string list in a DataGrid,but when I want to edit
it,the program will crash.
EDIT:
The compiler says: 'Edit item' is not allowed for this view.

No comments:

Post a Comment