以下是如何在ObservableCollection" OrderCollection"中获取基于列的行值的示例:
Double OrderSubTotal = (Double)0;
foreach (var data in this.OrderCollection)
{
Order orderData = (Order)data;
//MessageBox.Show(orderData.Product.SalesPrice.ToString());
OrderSubTotal = orderData.Product.SalesPrice;
}
this.OrderSum += OrderSubTotal;
答案 0 :(得分:0)
for (int i = 0; i < dataGrid.Items.Count; i++ )
{
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i);
foreach (var gridColumn in dataGrid.Columns)
{
if(gridColumn.Header == "Something")
{
// Do something
}
}
答案 1 :(得分:0)
foreach(object t in PaymentDataGrid.SelectedItems)
{
DataRowView row = t as DataRowView;
if (row != null)
{
var transactionId = (int)row[0];
}
}
这段代码非常适合检索每个选定行的指定列索引。