链接标签 C# - 显示它们的列表
我正在尝试将链接标签列表添加到列表视图。我这样做,
foreach (String s in values)
{
LinkLabel label = new LinkLabel();
label.Text = s;
txtBox.Controls.Add(label);
}
}
即使有更多项目,它仍然只向列表框中添加一项。有什么想法吗?
ps)我可以看出在迭代时添加断点和使用 console.writeline 有更多项目
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ListView
或ListBox
控件都不是真正设计用于承载子控件的。如果这就是您所需要的,那么您应该使用容器控件,例如
面板
。我建议使用TableLayoutPanel
或FlowLayoutPanel
可以自动管理其子控件的布局。Neither the
ListView
orListBox
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 aTableLayoutPanel
or aFlowLayoutPanel
that can automatically manage the layout of its child controls.我试过你的代码。
您正在做的是将控件添加到列表项而不是项目。
因此,当您检查 => txtbox.Items.Count = 0;和 txtbox.Controls.Count = 2
在 for 循环之后。
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.