我想在数据网格中显示一些值,而这些值不是来自数据库。 我正在创建一个POS,当用户输入一个项目时,它应该以数据网格形式显示给他/她。
答案 0 :(得分:0)
这是我尝试过的,我的错误是我没有绑定“名称”,“价格”,但现在我已经纠正它,现在它完美地运作
public struct MyData
{
public int Price { set; get; }
public string Name { set; get; }
}
public MainWindow()
{
InitializeComponent();
DataGridTextColumn grid_C1 = new DataGridTextColumn();
DataGridTextColumn grid_C2 = new DataGridTextColumn();
dGrid.Columns.Add(grid_C1);
dGrid.Columns.Add(grid_C2);
grid_C1.Binding = new Binding("Name");
grid_C2.Binding = new Binding("Price");
grid_C1.Header = "Name";
grid_C2.Header = "Price";
dGrid.Items.Add(new MyData { Name = "dumyText", Price = 2 });
dGrid.Items.Add(new MyData { Name = "dumyText", Price = 2 });
}