C1FlexGrid 绑定数据后我想显示其中一个对象的名称如以下例子,我想显示文章和名字,因为名字这列编辑控件使用DROPDOWN,数据库保存是保存用户id的,我是怎么也不能显示相关的内容?不知道能不能实现,如果不能实现使用什么方法可以?先表示感谢!
private List<NDARTICLE> InitData()
{
List<NDARTICLE> data = new List<NDARTICLE>();
data.Add(new NDARTICLE() { ARTICLE = "书1", USER = new NDUSER() { Id = 1, USERDM = "001", USERNAME = "张三" } });
data.Add(new NDARTICLE() { ARTICLE = "书2", USER = new NDUSER() { Id = 2, USERDM = "002", USERNAME = "李四" } });
data.Add(new NDARTICLE() { ARTICLE = "书3", USER = new NDUSER() { Id = 1, USERDM = "001", USERNAME = "张三" } });
data.Add(new NDARTICLE() { ARTICLE = "书4", USER = new NDUSER() { Id = 4, USERDM = "004", USERNAME = "王五" } });
data.Add(new NDARTICLE() { ARTICLE = "书5", USER = new NDUSER() { Id = 5, USERDM = "005", USERNAME = "赵六" } });
return data;
}
private void c1Button1_Click(object sender, EventArgs e)
{
this.c1FlexGrid1.AutoGenerateColumns = false;
//this.Cols[num].Format = "c";
//this.Cols[num].Name = info.ColumnName;
//string columnType = info.ColumnType;
//this.Cols[num].DataType = Type.GetType("System." + columnType);
//this.Cols[num].Format = info.DispFormat;
//this.Cols[num].WidthDisplay = info.ColumnWidth;
this.c1FlexGrid1.Cols.Count = 2;
this.c1FlexGrid1.Cols.Fixed = 0;
this.c1FlexGrid1.Cols[0].Name = "ARTICLE";
this.c1FlexGrid1.Cols[0].Caption = "文章";
this.c1FlexGrid1.Cols[0].Format = "c";
this.c1FlexGrid1.Cols[1].Name = "USER";
this.c1FlexGrid1.Cols[1].Caption = "姓名";
this.c1FlexGrid1.Cols[1].Format = "c";
//this.c1FlexGrid1.Cols[1].DataType = typeof(String);
List<NDARTICLE> data = InitData();
this.c1FlexGrid1.DataSource = new BindingList<NDARTICLE>(data);
int r = 1, c = 1;
foreach (NDARTICLE n in data)
{
NDUSER u = n.USER;
this.c1FlexGrid1.SetData(r, 1, u.USERNAME);
r++;
}
}
//数据对象类
public class NDARTICLE
{
public string ARTICLE { get; set; }
public NDUSER USER { get; set; }
}
public class NDUSER
{
public int Id { get; set; }
public string USERDM { get; set; }
public string USERNAME { get; set; }
public string PASSWORD { get; set; }
public int ISMANAGER { get; set; }
}
|
|