【问题标题】:Datagrid displays data in wrong rowsDatagrid 在错误的行中显示数据
【发布时间】:2016-04-09 06:37:27
【问题描述】:

我正在使用 Visual Studio 2015 制作一个使用 C# 和 EntityFrame 的程序。这是一个 WPF 项目。

问题是,当我从数据库加载数据时,datagridview 将数据显示在错误的行中。 2016//4/9, Rent, 10000 必须在同一行。但列是正确的。请看图片:

我正在加载数据如下:

using (var context = new MyDataEntities())
        {
            IList<MyTable> dataList = context.MyTable.ToList<MyTable>();
            dataGrid1.ItemsSource = dataList;
        }

为什么数据显示在错误的行中?任何建议表示赞赏。

【问题讨论】:

    标签: c# wpf entity-framework datagrid


    【解决方案1】:

    不确定您在数据网格的 xaml 上的定义,但可能是这样。如果您将您的设计附在上面会有所帮助。

    无改动 这是我的测试

    public class RowObj
        {
            public int Index { get; set; }
            public string Data { get; set; }
        }
    
    
    
     void Populate()
        {
            List<RowObj> model = new List<RowObj>();
            model.Add(new RowObj {  Index=1, Data="Apple"});
            model.Add(new RowObj { Index = 2, Data = "Cherry" });
            DG.ItemsSource = model;
            DG.Items.Refresh();
        }
    

    Output grid with 2 rows of data

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 2019-01-06
      相关资源
      最近更新 更多