数据绑定到DevExpress XtraGrid的问题 [英] Problem with data binding to DevExpress XtraGrid
问题描述
我创建了一个类:
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 = 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;
运行应用程序时,我得到一个空格。不知何故,我在设计时创建的列在运行时没有与数据正确填充。我尝试做同样的事情,没有在设计时创建的列,应用程序运行与正确填充的数据。我错过了一些东西
任何想要调试问题或
解决问题的想法将非常
赞赏。感谢提前
将列的FieldName属性设置为ID,StartTime,EndTime案件敏感!!!!)。此外,我建议您移动代码将网格的DataSource设置为窗体的Load事件。这应该可以帮助你。
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
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.
这篇关于数据绑定到DevExpress XtraGrid的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!