我正在用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;