微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何动态地在C#windows应用程序中的DataGridView单元格中添加表?

我正在用C#开发一个 Windows应用程序,我有一个DataGridView,目前显示数据源的值.我想添加一个列,其中每一行都有一个表.现在有没有办法动态地这样做?因为表格结构在每一行都会有所不同.

提前致谢.

编辑: – 我的意思是,我想动态地在单元格中插入一个表格.

当我尝试在每一行中动态添加TableLayoutPanel时,您可以看到实体详细信息列.

解决方法

1).试试MSDN的Mark Ridout的 TreeGridView并阅读他的 article使用它.

另请参阅使用Mark Ridout的TreeGridView的CodeProject DataGridView with Hierarchical Data Binding是否有用.

2).如果免费控制不起作用,请看看第三方(我不隶属于这些公司):

Devexpress XtraGrid
Telerik Gridview
Infragistics Grid
VIBlend DataGridView for WinForms
Janus Grid
xceed’s Grid

3).我很确定将TablePanelLayout添加到Grids单元格中并不是您想要的,这里是代码,因此您可以看到它对您自己有多么狡猾:

DataTable dt = new DataTable();
dt.Columns.Add("name");
for (int j = 0; j < 10; j++)
{
    dt.Rows.Add("");
}
this.dataGridView1.DataSource = dt;
this.dataGridView1.Columns[0].Width = 200;
//add tableLayoutPanel1 into the control collection of the DataGridView
this.dataGridView1.Controls.Add(tableLayoutPanel1);
//resize the row
this.dataGridView1.Rows[1].Height = 100;
//set its location and size to fit the cell
tableLayoutPanel1.Location = this.dataGridView1.GetCelldisplayRectangle(0,1,true).Location;
tableLayoutPanel1.Size = this.dataGridView1.GetCelldisplayRectangle(0,true).Size;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐