c#中如何将listbox中的内容添加到textbox中

指的是点击一下listbox中的文本,然后将该文本所在文件中关于该文本的内容添加到textbox中

①确保listbox中存储的文本名称,包括其所在完整路径
②在listbox的SelectedIndexChanged事件中,添加代码:
string[] contents=System.IO.File.ReadAllLines(@listbox.selectedItem);
foreach(string temp in contents)
{
textbox.appendText(temp);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-05
textbox1.text = listbox,selectItem.tostring();追问

你这个只能将选择的文本添加到textbox中
而不是将储存该文本文件中的信息添加到textbox中

追答

FileStream fs=new FileStream(listbox,selectItem.tostring();,FileMode.Open);
StreamReader sr = new StreamReader(fs,Encoding.Default);
string content = sr.ReadToEnd();
sr.Close();
fs.Close();
textbox1.text = content;

本回答被提问者采纳
第2个回答  2011-06-05
textbox1.text += "," + listbox,selectItem.tostring();
textbox1.text = textbox1.text.SubString(1);
相似回答