【发布时间】:2012-03-24 06:04:28
【问题描述】:
我需要一些帮助,因为我对 C# 比较陌生。我基本上是在尝试克隆一个 datagridview 组件属性(行/列内容不同)。
基本上我有一个标签页控件...并且在运行时,如果用户想要添加另一个表,则会创建一个新页面,其中包含与现有 datagridview 组件相同的属性的新 datagridview:
string newpagetitle = "tab_page" + (tab_control01.TabCount + 1);
TabPage newTab_page = new TabPage(newpagetitle);
DataGridView clonedDGV = new DataGridView();
clonedDGV = this.dataGridView1; //need to clone this
clonedDGV.Name=("DataGridView" + tab_control01.TabCount + 1);
clonedDGV.DataSource = exam_Results_Table;
newTab_page.Controls.Add(clonedDGV);
this.tab_control01.TabPages.Add(newTab_page);
【问题讨论】:
-
我不认为你会以这种方式到达你想要的地方......我将为这种网格创建一个数据模板并将其绑定到数据源(视图模型)。如果您的用户创建了一个新表(新数据源),您可以使用相同的数据模板将其绑定到一个新的网格实例。这会导致网格的“视觉克隆”,其中包含新数据。
标签: c# winforms datagridview clone