label控件怎么显示listbox的所有内容?

landry1234 2009-04-28 12:37:59
一个listbox里有好几行,我想用label把它的所有值都显示出来,能吗?如果不行,显示listbox里的一行也可以,代码怎样写?
...全文
179 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
simonezhlx 2009-04-28
  • 打赏
  • 举报
回复
StringBuilder sLableText = new StringBuilder();
foreach(object text in listBox1.Items )
{
sLableText.Append(text.ToString() );
}
Label1.Text = sLableText.ToString();
teerhu 2009-04-28
  • 打赏
  • 举报
回复
string str=string.Empty;
foreach(ListItem item in listbox1.Items)
{
str+=(item.value+";")
}
label1.Text=str;
wuqianghappy 2009-04-28
  • 打赏
  • 举报
回复
把值读入数组里,之后在把值显示在label 里!
zgke 2009-04-28
  • 打赏
  • 举报
回复
string _Value = "";
for (int i = 0; i != listBox1.Items.Count; i++)
{
_Value += listBox1.Items[i].ToString() + "\r\n";
}
label1.Text = _Value;
marvelstack 2009-04-28
  • 打赏
  • 举报
回复
如果把多行值显示在一行上只能有规则的进行拼凑在一起,规则是你定,
建议字符串构建过程中使用StringBuilder,而不是简单的String1 + String 2,至于为什么就不多说了。
landry1234 2009-04-28
  • 打赏
  • 举报
回复
太感谢了

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧