Link Labels c# - displaying a list of them

假如想象 提交于 2019-12-20 02:14:06

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4712191/link-labels-c-sharp-displaying-a-list-of-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!