DX控件高手请帮帮我.gridcontrol 绑定list,关于更改列名,或者隐藏列,谢谢大家

txwtony 2010-11-08 03:37:08
将一个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类里的属性字段不变
...全文
549 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
duanzhi1984 2011-01-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sudianbo 的回复:]
命名列名 this.gridColumn1.Caption 列名主要用于显示; 绑定数据this.gridColumn1.FieldName 用LIST里的实体的属性名赋值。
例如:
//
// gridColumn1
//
this.gridColumn1.Caption = "公司名称";
this.gridColumn1.FieldName = "Co……
[/Quote]
顶。。。
_三皮_ 2011-01-31
  • 打赏
  • 举报
回复
命名列名 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;
acns 2011-01-31
  • 打赏
  • 举报
回复
在grid desginer里加一个new level的view, 把你子list的字段添到新view里去。
qldsrx 2011-01-31
  • 打赏
  • 举报
回复
Caption 就是列显示名,很多地方都是这个专有名词,楼主计算机英语不行啊,专有名词认识不多。
ghj5454 2011-01-28
  • 打赏
  • 举报
回复
这个也是可以做到的。

你在gridControl里需要定义2个gridview,和你类的结构是一样带有父子关系的结构。

因为你在对GridControl进行绑定之后,gridControl会默认建立gridview的关系,关系名默认为你的List对应的属性名称,即:Lstchild,所以你只需要将你的level名称改成Lstchild,即可。

你可以对子gridview进行自定义列名。

有问题联系我,QQ:76481292
txwtony 2010-11-08
  • 打赏
  • 举报
回复
回2楼:谢谢帮顶,不过您好像误解我的意思了.
期待高手来
garfieldzf 2010-11-08
  • 打赏
  • 举报
回复
禁止编辑列: AllowEdit=false
garfieldzf 2010-11-08
  • 打赏
  • 举报
回复
用DEV还没碰到过这种问题

友情帮顶

等待方案....

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧