我要遍历一下listbox里的内容,请问怎样获取到啊?

kami_bin 2012-05-06 08:53:14
我试过用listbox.Items[int n].toString()
但是得出的是一个空值。。。求高人指点
...全文
268 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kami_bin 2012-05-06
  • 打赏
  • 举报
回复
搞定了,原来是我add进listbox里的时候用了stringbuilder,我改成string就可以了,不过还是谢谢你们哈,O(∩_∩)O哈哈~
[Quote=引用 4 楼 的回复:]

引用 3 楼 的回复:
我是winform的
好像不行啊,会出现下面错误的:
无法将类型为“System.Text.StringBuilder”的对象强制转换为类型“System.String”。

引用 1 楼 的回复:

winfrom版本:
foreach (string itemValue in listBox1.Items)
{
textBox1.Text += ……
[/Quote]
orochiheart 2012-05-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
我是winform的
好像不行啊,会出现下面错误的:
无法将类型为“System.Text.StringBuilder”的对象强制转换为类型“System.String”。

引用 1 楼 的回复:

winfrom版本:
foreach (string itemValue in listBox1.Items)
{
textBox1.Text += itemValue;
}
……
[/Quote]
try

foreach (string itemValue in listBox1.Items)
{
textBox1.AppendText(itemValue);
}

kami_bin 2012-05-06
  • 打赏
  • 举报
回复
我是winform的
好像不行啊,会出现下面错误的:
无法将类型为“System.Text.StringBuilder”的对象强制转换为类型“System.String”。
[Quote=引用 1 楼 的回复:]

winfrom版本:
foreach (string itemValue in listBox1.Items)
{
textBox1.Text += itemValue;
}
web版本:

foreach (ListItem item in ListBox1.Items)
{
TextBox1.Text += item.Text ;
}
[/Quote]
orochiheart 2012-05-06
  • 打赏
  • 举报
回复

string par=String.Empty;

foreach(ListItem ItemValue in Listbox1.Items)

{

par=ItemValue.Value;

}

Textbox2.Text=par;


netshuiwa 2012-05-06
  • 打赏
  • 举报
回复
winfrom版本:
foreach (string itemValue in listBox1.Items)
{
textBox1.Text += itemValue;
}
web版本:

foreach (ListItem item in ListBox1.Items)
{
TextBox1.Text += item.Text ;
}

111,125

社区成员

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

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

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