更新数据网格内的值的最佳方法是什么 - 以编程方式? 我正在使用以下代码并且卡住了。以下行给出错误: drv [" bill_total"] = list_BillTotals [i];或使用索引:这是第6列 drv [5] = list_BillTotals [i];
说:无法设置bill_total或找不到列号。 5
DataSet dataset = m_billMaster.getAllBills(); dg_bills.DataContext = dataset;
List<double> list_BillTotals = m_billMaster.getAllBillTotals();
DataRowView drv;
for (int i = 0; i < list_BillTotals.Count; i++)
{
drv = ((DataRowView)dg_bills.Items[i]);
if (drv != null)
{
drv["bill_total"] = list_BillTotals[i];
}
}
我的XAML看起来像这样:
<DataGrid x:Name="dg_bills"
Grid.Row="1"
IsReadOnly="True"
ItemsSource="{Binding Path=bill_master}"
AutoGenerateColumns="False"
SelectionChanged="dg_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="#" Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={local:RowToIndexConverter}}"/>
<DataGridTextColumn Header="Customer" Binding="{Binding Path=bill_customer}"/>
<DataGridTextColumn Header="Bill No." Binding="{Binding Path=bill_billNum}"/>
<DataGridTextColumn Header="Bill Date" Binding="{Binding Path=bill_billDate, StringFormat=\{0:dd-MM-yyyy\}}"/>
<DataGridTextColumn Header="Transports(#)" Binding="{Binding Path=bill_numTrns}"/>
<DataGridTextColumn Header="Bill Total" Binding="{Binding Path=bill_total}" />
<DataGridTextColumn Header="Created At" Binding="{Binding Path=bill_createDate, StringFormat=\{0:dd-MM-yyyy\}}"/>
</DataGrid.Columns>
</DataGrid>
请分享您的知识和经验。 随时欢迎任何建议。 提前谢谢。