下面DataTable中第二列的名称是“f / g”,当我运行它时,我没有看到屏幕第二列中的值,为什么会这样?
顺便说一句,当我把它变成“f:g”时它会起作用,但是“f [g”没有。 DataTable resultDataTable = new DataTable();
DataColumn id_column = new DataColumn();
id_column.DataType = System.Type.GetType("System.String");
id_column.ColumnName = "ID";
id_column.ReadOnly = true;
id_column.Unique = true;
resultDataTable.Columns.Add(id_column);
DataColumn f_column = new DataColumn();
f_column.DataType = System.Type.GetType("System.Double");
f_column.ColumnName = "f/g";
f_column.ReadOnly = true;
resultDataTable.Columns.Add(f_column);
foreach (var entry in results.Results)
{
DataRow dr = resultDataTable.NewRow();
dr[0] = entry.Key;
dr[1] = entry.Value;
resultDataTable.Rows.Add(dr);
}
ResultsDataGrid.ItemsSource = resultDataTable.AsDataView();
答案 0 :(得分:5)
好的,我不知道它为什么不起作用,但我确实找到了一种解决方法,使用Column Caption属性并在DataGrid中实现AutoGeneratingColumn事件:
private void ResultsDataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
var dGrid = (sender as DataGrid);
if (dGrid == null) return;
var view = dGrid.ItemsSource as DataView;
if (view == null) return;
var table = view.Table;
e.Column.Header = table.Columns[e.Column.Header as String].Caption;
}
基本上它采用Caption属性中的任何内容并将其放在DataGrid列标题中,甚至是“f / g”。
答案 1 :(得分:-3)
尝试改变 " F / G"
到
" //˚FG"或者f [/] g
逃离角色