数据绑定到 DevExpress XtraGrid 的问题

发布于 2024-10-28 05:22:40 字数 1605 浏览 0 评论 0原文

我有一个 XtraGrid 放到 Winform 上。我创建了 3 个名为 ID、StartTime 和 EndTime 的未绑定列,并将它们的未绑定类型分别设置为 Int、DateTime 和 DateTime。 我创建了一个类:


public class Data
{
    public Data(int id, DateTime startTime, DateTime endTime)
    {
        this.id = id;
        this.startTime = startTime;
        this.endTime = endTime;
    }
    private int id;
    private DateTime startTime;
    private DateTime endTime;
    public int ID
    {
        get { return id; }
        set { id = value; }
    }
    public DateTime StartTime
    {
        get { return startTime; }
        set { startTime = value; }
    }
    public DateTime EndTime
    {
        get { return endTime; }
        set { endTime = value; }
    }
}

在表单构造函数中,我创建了一个列表,并在运行时将该列表绑定到我的网格控件

        List<Data> list = new List<Data>();
        list.AddRange(new Data[] {
                    new Data(1, Convert.ToDateTime("1:00:00 AM"),
                    Convert.ToDateTime("3:00:00 AM")),
                    new Data(2, Convert.ToDateTime("8:00:00 PM"),
                    Convert.ToDateTime("8:30:00 PM")),
                    new Data(3, Convert.ToDateTime("12:00:00 PM"),
                    Convert.ToDateTime("1:00:00 AM")),
                    new Data(4, Convert.ToDateTime("2:00:00 AM"),
                    Convert.ToDateTime("3:00:00 AM"))
                    });
        gridControl1.DataSource = list; 

。当运行应用程序时,我得到一个空网格。不知何故,我在设计时创建的列在运行时没有正确填充数据。我尝试做同样的事情,在设计时没有创建列,并且应用程序使用正确填充的数据运行。我缺少一些东西。

任何调试问题的想法或 解决问题就会非常 赞赏。提前致谢

I have a XtraGrid dropped on to a Winform. I have created 3 unbound columns named ID, StartTime and EndTime and set their unbound types as Int, DateTime and DateTime respectively.
I have created a class:


public class Data
{
    public Data(int id, DateTime startTime, DateTime endTime)
    {
        this.id = id;
        this.startTime = startTime;
        this.endTime = endTime;
    }
    private int id;
    private DateTime startTime;
    private DateTime endTime;
    public int ID
    {
        get { return id; }
        set { id = value; }
    }
    public DateTime StartTime
    {
        get { return startTime; }
        set { startTime = value; }
    }
    public DateTime EndTime
    {
        get { return endTime; }
        set { endTime = value; }
    }
}

In the form constructor I created a List and bind the list to my gridcontrol at runtime

        List<Data> list = new List<Data>();
        list.AddRange(new Data[] {
                    new Data(1, Convert.ToDateTime("1:00:00 AM"),
                    Convert.ToDateTime("3:00:00 AM")),
                    new Data(2, Convert.ToDateTime("8:00:00 PM"),
                    Convert.ToDateTime("8:30:00 PM")),
                    new Data(3, Convert.ToDateTime("12:00:00 PM"),
                    Convert.ToDateTime("1:00:00 AM")),
                    new Data(4, Convert.ToDateTime("2:00:00 AM"),
                    Convert.ToDateTime("3:00:00 AM"))
                    });
        gridControl1.DataSource = list; 

When run the application, I get an empty grid. Somehow the columns that I created at design time are not filled correctly with the data at runtime. I try to do the same thing with no columns created at design time and the application run with correctly filled data. I am missing something.

Any ideas to debug the problem or
solve the problem will be very
appreciated. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开柳相依 2024-11-04 05:22:40

将列的 FieldName 属性设置为 ID、StartTime、EndTime(区分大小写!!!)。另外,我建议您移动代码以将网格的数据源设置为表单的加载事件。这应该对你有帮助。

Set the FieldName property of your columns to ID, StartTime, EndTime (Case Sensitively!!!!). Also, I would suggest that you move your code to set the grid's DataSource to the form's Load event. This should help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文