0

I am dynamically creating tabs and then populating them with a datagridview. I can successfully create multiple tabs, but when I create a new tab, while its contents show as I expect, all the other tabs are blank.

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);
stuartd
  • 70,509
  • 14
  • 132
  • 163
DaveS
  • 105
  • 1
  • 1
  • 8
  • Where do you instantiate `lv`? – squillman Jul 09 '18 at 17:54
  • It's filescope... defined at the top of the class – DaveS Jul 09 '18 at 17:56
  • 2
    If you only have __one__ lv it will be only on __one__ page. you can __move__ it around but it will still be only __one__ control. Best write a factory method that can create instances of the lv you can then add to all pages you want.. Or include a line like `ListView lv = new ListView();` at the top – TaW Jul 09 '18 at 18:03
  • That was it.. thanks – DaveS Jul 09 '18 at 18:09
  • You also ignore your column2. – LarsTech Jul 09 '18 at 18:09
  • What do you mean? it gets created – DaveS Jul 09 '18 at 18:56
  • Use the @ sign in front of a user name to contact them in contacts here. Look at the variable name you use under the column2 declaration: it's all properties for column, which you already declared earlier in the code. – LarsTech Jul 09 '18 at 19:06

0 Answers0