![](/img/trans.png)
[英]Colorize Autogenerated Columns from DataTable in wpf DataGrid
[英]WPF DataGrid not displaying values of DataTable in certain columns
我有一個程序對CSV文件進行一些處理,並且正在生成一個DataTable作為輸出。 我將其綁定到DataGrid像這樣:
<DataGrid Name="GridTable" ItemsSource="{Binding OutputData}" />
一切似乎都正常。 生成DataTable,更新DataGrid。 但莫名其妙的列(類型Double)似乎沒有顯示其數據。 第一列(int類型)可以正常工作:
當我再次檢查DataTable結構時,它就在那里,而且所有類型都正確。 我沒有例外:
數據綁定在顯示列時很明顯,並且在第一列中具有正確的值。
有人遇到過嗎? 干杯
你用過
<DataGrid.Columns>
<DataGridTextColumn Header="" Binding="{Binding }"/>
</DataGrid.Columns>
它應該處理雙打沒有問題
Marcin上面的回答使我嘗試單獨綁定列,這使我在這里:以編程方式將列和行添加到WPF Datagrid
解決方案是這樣的:
if (OutputData != null)
{
foreach (DataColumn col in OutputData.Columns)
{
GridTable.Columns.Add(
new DataGridTextColumn
{
Header = col.ColumnName,
Binding = new Binding(string.Format("[{0}]", col.ColumnName))
});
}
GridTable.DataContext = OutputData;
}
我知道已經有很長時間了,但是如果您使用的是db first集成,那么在datagrid和excel文件中不會顯示可空值。 您基本上可以將您的nullable轉換為int
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.