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

标签 c# winforms datagridview windows-applications

我正在用 C# 开发 Windows 应用程序,我有一个 DataGridView,当前显示数据源的值。我想添加一个列,其中每一行都有一个表。现在有什么办法可以动态地做到这一点吗?因为每一行的表结构都会有所不同。

提前致谢。

编辑:-我的意思是,我想在单元格中动态插入表格。

enter image description here

当我尝试在每一行中动态添加 TableLayoutPanel 时,您可以看到 Entity Details 列显示了这一点。

最佳答案

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

enter image description here

另请参阅此 CodeProject DataGridView with Hierarchical Data Binding使用 Mark Ridout 的 TreeGridView 很有用。

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

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, 1, true).Size;

关于c# - 如何在 C# Windows 应用程序中动态地在 DataGridView 的单元格中添加表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16239255/

相关文章:

C# 将 uint[] 转换为 byte[]

c# - VB.NET Select...C# 中等效的 Case 语句

c# - Treenode 存在但 treenode.nodes.ContainsKey ("Nodename") 等于 false

winforms - WinForms DataGridView 中的水平滚动条

c# - 读取压缩文件并写入新文件将不允许解压

c# - 显示 GridView 中的行数

c# - 动态创建winforms可执行文件C#

c# - 如何在 WinForms 项目中将 XML 用作 DataGridView 的数据源?

c# - 如何更改datagridview的值?

c# - 禁止用户选择彼此不相邻的多行?