链接标签 C# - 显示它们的列表

发布于 2024-10-12 16:10:15 字数 338 浏览 9 评论 0原文

我正在尝试将链接标签列表添加到列表视图。我这样做,

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云裳 2024-10-19 16:10:15

ListViewListBox 控件都不是真正设计用于承载子控件的。

如果这就是您所需要的,那么您应该使用容器控件,例如 面板。我建议使用 TableLayoutPanel FlowLayoutPanel 可以自动管理其子控件的布局。

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.

猥琐帝 2024-10-19 16:10:15

我试过你的代码。
您正在做的是将控件添加到列表项而不是项目。

因此,当您检查 => 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文