views:

53

answers:

4

I'm searching files and returning lines that include the search text, and I'm not really sure the best way to display the information I get. Every time I get a match, I want to show, in some sort of control, the File it came from, and the whole text line. (aka streamreader.ReadLine() result). First I tried just putting it all in a read-only text box, but it doesn't have a scroll bar.

What is the best form control to help me display this data neatly?

+1  A: 

The text box should do just fine. Just set MultiLine to true and ScrollBars to Auto (or Vertical, whichever suits you best).

Fredrik Mörk
well I had the mutliline. But the other problem is that it doesn't seem to recognize when i add a \n to it.
The.Anti.9
@The.Anti.9: did you try adding the text using `yourTextBox.AppendText(lineToAdd + Environment.NewLine);`?
Fredrik Mörk
A: 

Your best bet would probably be either a Listbox, or a DataGridView.

Also maybe have a look at Environment.NewLine Property

astander
A: 

A ListView will work for this. Set its View property to Details, and add two columns in the designer (call them FileName and FirstLine or something, and play around with the widths as you like).

You add a new line like this:

string FileName = @"c:\file1.txt";
string FirstLine = "This is the first line of text from the file";
ListViewItem item = new ListViewItem(FileName);
item.SubItems.Add(FirstLine);
listView1.Items.Add(item);
MusiGenesis
A: 

You could use a list box to list the files in which the text was found, and then, a text box containing the text you want to show. You should be able to work if you do like Fredrik Mörk said.

npinti