我試圖讓dataGrid1可編輯。我讀過,我可以創建一個類實例到List然後將其分配給DataGrid.ItemSource。這可能只是2行代碼,但仍然掛在如何使用下面的代碼。有任何想法嗎?謝謝!在WPF中編輯DataGrid
public class MyData
{
public string street { set; get; }
public string town { set; get; }
}
DataGridTextColumn col1 = new DataGridTextColumn();
col1.Binding = new Binding("name");
dataGrid1.Columns.Add(col1);
dataGrid1.Items.Add((new MyData() { street = "5th ave", town = "neverland"}));
好的,謝謝你的幫助。仍然試圖習慣張貼在stackoverflow上。這是我改變了,它爲我工作。
List<MyData> MyListBox1 =new List<MyData>();
MyListBox1.Add(new MyData() { street = "5th ave", town = "neverland"}));
List<MyData> MyListBox1 =new List<MyData>();
我也不得不使用System.Collections.Generic添加
;
嗯,我有種重做項目。我會告訴你我在下面的代碼中做了什麼。謝謝。 – mdietz
@MichaelDietz:請在上面而不是下面,評論不適合代碼。 –