如何在自动生成的选项卡上创建DataGridsViews
本文关键字:创建 DataGridsViews 选项 自动生成 | 更新日期: 2023-09-27 18:04:02
当加载我的excel文件与许多工作表时,我取每个工作表的名称,并在tabControl中自动生成选项卡。这个作品。接下来我有麻烦,所以一个新的和不同的dataGridView得到生成在每个标签。这是到目前为止这部分的代码
foreach (DataRow row in dt1.Rows) {
comboBox1.Items.Add(row["TABLE_NAME"].ToString());
tabControl2.TabPages.Add(row["TABLE_NAME"].ToString());
DataGridView grid = new DataGridView();
TabPages.Controls.Add(grid); // red line under TabPages **********
}
把新的TabPage放到一边,这样你就可以给它添加控件了:
foreach (DataRow row in dt1.Rows) {
string name = row["TABLE_NAME"].ToString();
var tabPage = new TabPage(name);
var grid = new DataGridView();
tabPage.Controls.Add(grid);
comboBox1.Items.Add(name);
tabControl2.TabPages.Add(tapPage);
}