我在我的WPF應用程序中有一個datagrid,我想在按鈕click中獲取列表中的所有行值。我嘗試了一些方法,但我只獲取了最後一個Row值...如何從WPF中的數據網格中獲取所有行
private async void Save_Btn_Click(object sender, RoutedEventArgs e)
{
pojo rowdata = new pojo();
int rowcount = calendarmstrDG.Items.Count;
List<pojo> pojolist = new List<pojo>();
var rows = (calendarmstrDG).SelectedItems;
for (int i = 1; i < rowcount - 1; i++)
{
pojo sda = (pojo)calendarmstrDG.SelectedItems;
pojolist.Add(sda);
}
}
這裏calendarmstrDG是我的DataGrid的名字...... POJO是我的模型類的名字......
public class pojo
{
public string Prefix { get; set; }
public int Year { get; set; }
public int Quarter { get; set; }
public int SerialNo { get; set; }
public string From { get; set; }
public string To { get; set; }
public string PeriodName { get; set; }
}
1.您只訪問選定的項目,是否有意? 2.在你的for循環中,你沒有使用你的「我」來逐行選擇 – royalTS
幫我準確的代碼..我想要所有的行 – Markz