创建新标签页时,标签页内容已清除

时间:2018-07-09 17:46:56

标签: c# winforms tabcontrol

我正在动态创建选项卡,然后使用datagridview填充它们。我可以成功创建多个选项卡,但是当我创建一个新选项卡时,尽管其内容按预期显示,但所有其他选项卡都为空白。

TabPage t = new TabPage();
t.Text = txtProjName.Text;

lv.Name = "lv";
lv.Bounds = new Rectangle(new Point(10, 10), new Size(3000, 2000));
lv.AllowUserToAddRows = true;
lv.AllowUserToDeleteRows = true;
lv.AllowUserToOrderColumns = false;

lv.Columns.Add("id", "id");
lv.Columns.Add("Task", "Task");
lv.Columns.Add("Status", "Status");
lv.Columns.Add("Value", "Value");
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
{
    column.HeaderText = "Sensitivity";
    column.Name = "Sensitivity";
    column.AutoSizeMode =
        DataGridViewAutoSizeColumnMode.DisplayedCells;
    column.FlatStyle = FlatStyle.Standard;
    column.ThreeState = false;
    column.CellTemplate = new DataGridViewCheckBoxCell();
}

lv.Columns.Insert(3, column);
DataGridViewCheckBoxColumn column2 = new DataGridViewCheckBoxColumn();
{
    column.HeaderText = "Priority";
    column.Name = "Priority";
    column.AutoSizeMode =
        DataGridViewAutoSizeColumnMode.DisplayedCells;
    column.FlatStyle = FlatStyle.Standard;
    column.ThreeState = false;
    column.CellTemplate = new DataGridViewCheckBoxCell();
}

lv.Columns.Insert(4, column2);
lv.Columns.Add("Due", "Due");
lv.Columns.Add("Assigned", "Assigned To");
lv.Columns.Add("Notes", "Notes");

t.Controls.Add(lv);


lv.Columns["id"].Visible = false;

lv.CellValueChanged += Task_CellValueChanged;

tcProjectTabs.TabPages.Add(t);

0 个答案:

没有答案