我正在用 C# 开发 Windows 应用程序,我有一个 DataGridView
,当前显示数据源的值。我想添加一个列,其中每一行都有一个表。现在有什么办法可以动态地做到这一点吗?因为每一行的表结构都会有所不同。
提前致谢。
编辑:-我的意思是,我想在单元格中动态插入表格。
当我尝试在每一行中动态添加 TableLayoutPanel
时,您可以看到 Entity Details
列显示了这一点。
最佳答案
1).试用 MSDN 的 Mark Ridout 的 TreeGridView并阅读他的 article关于使用它。
另请参阅此 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/