DX控件高手请帮帮我.gridcontrol 绑定list,关于更改列名,或者隐藏列,谢谢大家
将一个list绑定到gridcontrol上.如果这个list里的某一个属性是一个collection.gridcontrol会自动将这个collection展开为一个新的view,但是这个新的view的列名无法重命名,并且这个view的列名就是改集合里的属性的名称.求教高手,如何重命名子view里的列的名字..代码如下public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
List<stu> lststu = new List<stu>();
lststu.Add(new stu("A","tang"));
gridControl1.DataSource = lststu;
}
}
public class stu
{
private string _classno;
public string Classno
{
get { return _classno; }
set { _classno = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
public stu(string cn,string name)
{
this._classno = cn;
this._name = name;
this.lstchild = new List<hobby>();
this.lstchild.Add(new hobby("1", "ss"));
this.lstchild.Add(new hobby("2","nn"));
}
private List<hobby> lstchild;
public List<hobby> Lstchild
{
get { return lstchild; }
set { lstchild = value; }
}
}
public class hobby
{
private string _id;
public string Id
{
get { return _id; }
set { _id = value; }
}
private string _hobby;
public string Hobby
{
get { return _hobby; }
set { _hobby = value; }
}
public hobby(string id, string hb)
{
this._id = id;
this._hobby = hb;
}
}
再run designer里只能更改班级的名字,但无法更改子view中id列和hobby列的列名.
我希望吧id改成学号,而hobby类里的属性字段不变 --------------------编程问答-------------------- 用DEV还没碰到过这种问题
友情帮顶
等待方案.... --------------------编程问答-------------------- 禁止编辑列: AllowEdit=false --------------------编程问答-------------------- 回2楼:谢谢帮顶,不过您好像误解我的意思了.
期待高手来 --------------------编程问答-------------------- --------------------编程问答-------------------- 这个也是可以做到的。
你在gridControl里需要定义2个gridview,和你类的结构是一样带有父子关系的结构。
因为你在对GridControl进行绑定之后,gridControl会默认建立gridview的关系,关系名默认为你的List对应的属性名称,即:Lstchild,所以你只需要将你的level名称改成Lstchild,即可。
你可以对子gridview进行自定义列名。
有问题联系我,QQ:76481292 --------------------编程问答-------------------- 命名列名 this.gridColumn1.Caption 列名主要用于显示; 绑定数据this.gridColumn1.FieldName 用LIST里的实体的属性名赋值。
例如:
//
// gridColumn1
//
this.gridColumn1.Caption = "公司名称";
this.gridColumn1.FieldName = "CompanyName";
this.gridColumn1.Name = "gridColumn1";
this.gridColumn1.OptionsColumn.AllowEdit = false;
this.gridColumn1.Visible = true;
this.gridColumn1.VisibleIndex = 0; --------------------编程问答--------------------
顶。。。 --------------------编程问答-------------------- Caption 就是列显示名,很多地方都是这个专有名词,楼主计算机英语不行啊,专有名词认识不多。 --------------------编程问答-------------------- 在grid desginer里加一个new level的view, 把你子list的字段添到新view里去。
补充:.NET技术 , C#