hi
excuse me (i can,t speak en good)
---------------------------------
my project have 15 text file (A.txt, B.txt & ...)
and have a listbox with items(A, B, & ...)
i want ...
when click in a item (A) from listbox ... open file (A.txt) in richtextbox !
how to do it ?
plz help ...
tanks
Listbox items
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 28, 2014, 7:35 AM EDT
Hemant SrivastavaRank #581 · 4.2K reputationPosted Jul 28, 2014, 9:57 AM EDT
//Directory where all the data files are kept
string sDirectory = @"D:\CSharpProject\MyData\";
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string sFilePath = sDirectory + listBox1.SelectedItem.ToString().Trim() + ".txt";
LoadMyFile(sFilePath);
}
public void LoadMyFile(string filename)
{
if (File.Exists(filename))
{
// Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(filename, RichTextBoxStreamType.PlainText);
}
else
{
MessageBox.Show("File doesn't exist in the folder : " + sDirectory );
}
}