The.Anti.9
The.Anti.9

Reputation: 44678

Displaying Data on the Windows Form

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?

Upvotes: 0

Views: 248

Answers (4)

npinti
npinti

Reputation: 52185

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.

Upvotes: 0

MusiGenesis
MusiGenesis

Reputation: 75296

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);

Upvotes: 0

Adriaan Stander
Adriaan Stander

Reputation: 166406

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

Also maybe have a look at Environment.NewLine Property

Upvotes: 0

Fredrik Mörk
Fredrik Mörk

Reputation: 158319

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

Upvotes: 1

Related Questions