3

I am trying to add a list of linked lables to a listview. I amd doing so like this

        foreach (String s in values)
        {
            LinkLabel label = new LinkLabel();
            label.Text = s;
            txtBox.Controls.Add(label);
        }
    }

It keeps adding just one item to the listbox even tho there are more. Any ideas?

ps) i can tell there are more items from adding a breakbpoint and using console.writeline when iterating

Thanks

tom
  • 4,911
  • 11
  • 37
  • 39

2 Answers2

2

Neither the ListView or ListBox controls are really designed to host child controls.

If that's what you need, then you should be using a container control, such as a Panel. I recommend using either a TableLayoutPanel or a FlowLayoutPanel that can automatically manage the layout of its child controls.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
0

I tried your code. What you are doing is adding control to listitem and not items.

Thus, when you check => txtbox.Items.Count = 0; and txtbox.Controls.Count = 2 after the for loop.

iTSrAVIE
  • 846
  • 3
  • 12
  • 26