我有一个错误,您能帮我吗? [英] I have an error, can you help me?

查看:42
本文介绍了我有一个错误,您能帮我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写此代码时出现错误:

I have an Error when I write this code :

for (int i = 0; i < ListBox1.Items.Count - 1; i++)
{
  if (ListBox1.Items[i].Selected)
    TextBox1.Text = ListBox1.Items[i].Text;
}

return null;

推荐答案


如果要循环选择的项目,则使用ListBox的SelectedItems属性:


Hi,
if you want to loop though selected items just use SelectedItems property of ListBox:


for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
{
    textBox1.Text += listBox1.SelectedItems[i].ToString() + "\r\n";
}


您遇到什么错误?在此处粘贴异常代码
what error you got? paste the exception code here


我想您要将列表框的选定项添加到文本框中.为此

首次初始化
I think you want to add the selected item of list box into the text box.for that

first initialise
TextBox1.Text=string.empty;





TextBox1.Text += ListBox1.Items[i].Text;




or

TextBox1.Text =TextBox1.Text+ ListBox1.Items[i].Text;


这篇关于我有一个错误,您能帮我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆