如何动态地在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;

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...