我在下面做了一個代碼,將數據表綁定到數據網格與動態列,這些數字取決於最終用戶的決定。它會創建正確數量的包含標題的列和行。但問題是每個單元格不顯示任何內容(空單元格)。你能告訴我在下面的代碼中有什麼問題嗎?我非常感謝你的幫助。將數據表綁定到數據網格
string[] filenames;
filenames = read.Filenames;
DataTable tvsa = new DataTable();
for (int i = 0; i < filenames.Length; i++)
{
double[] a_raw = arsconv.Ama;
// Define the columns of the table.
DataColumn column= new DataColumn();
column.DataType = System.Type.GetType("System.Double");
column.ColumnName = filenames[i];
tvsa.Columns.Add(column);
//Define rows
DataRow dr;
for (int l = 0; l < a_raw.Length; l++)
{
dr = tvsa.NewRow();
dr[filenames[i]] = a_raw[l];
tvsa.Rows.Add(dr);
}
}
datagrid_accu.ItemsSource = tvsa.DefaultView;
XAML:
<DataGrid Name="datagrid_accu" ItemsSource="{Binding tvsa.DefaultView}" Width="Auto" AutoGenerateColumns="True" >
<DataGrid.Columns>
</DataGrid.Columns>
</DataGrid>
如果去掉'的ItemsSource =「{結合tvsa.DefaultView}'在XAML?創建 – Peter
表,但沒有值仍然感謝, – user3170073