List Box question

  • Thread starter Thread starter Patrick De Ridder
  • Start date Start date
P

Patrick De Ridder

Using a list box to display a text file, I am having to adjust the
length of the lines to fit the list box, (1) is there a way around
this? (2) Can one use rtf files with a list box, does that have coding
consequences when using the list box, if so which?
Many thanks.
 
Patrick,

Are you sure you are using a list box and not a textbox? The two have
very different functionality.

Why do you have to adjust the length of the lines to fit the textbox?
The textbox should wrap around the lines automatically.

If you use RTF files, then you will have to use a RichTextBox, which has
the same base as the TextBox class, but with more functionality.

Hope this helps.
 
Patrick,

Are you sure you are using a list box and not a textbox? The two have
very different functionality.

Why do you have to adjust the length of the lines to fit the textbox?
The textbox should wrap around the lines automatically.

If you use RTF files, then you will have to use a RichTextBox, which has
the same base as the TextBox class, but with more functionality.

Hope this helps.

I am using a list box because a text box takes only one line and I
have many lines to display. I am doing it like so:

for(int i = 0; i<k;i++)
{
show=" "+strR2.ReadLine();
}
listBox1.DataSource = show;

The lines that overrun the width are not wrapped. How should I do this
better? And in the case of a rich text box: how do I bind many lines
of rich text from a file to a rich text box?

Many thanks.
 
Patrick,

This should not matter if your working with a WebForm or a WinForm.
What it sounds like you need to do is use a Textbox.

Set the Textbox property Multiline to true. And WordWrap to you needs.
Then resize the Textbox.

You can load a file by just setting the TextBox.Text property.
But if you were using the Listbox because you wanted to know what line
the user had selected then when loading the file split your string on
"\r\n" then assign the string array to the Lines property.

Also as another tip. To speed up the load, add all the file lines into
a System.Text.StringBuilder object first. Then assign the
StringBuilder.ToString() results to the TextBox.Text

Hope this helps.

Glen Jones MCSD
NewData
 
Patrick,

This should not matter if your working with a WebForm or a WinForm.
What it sounds like you need to do is use a Textbox.

Set the Textbox property Multiline to true. And WordWrap to you needs.
Then resize the Textbox.

You can load a file by just setting the TextBox.Text property.
But if you were using the Listbox because you wanted to know what line
the user had selected then when loading the file split your string on
"\r\n" then assign the string array to the Lines property.

Also as another tip. To speed up the load, add all the file lines into
a System.Text.StringBuilder object first. Then assign the
StringBuilder.ToString() results to the TextBox.Text

Hope this helps.

Glen Jones MCSD
NewData

One you have displayed something in a textBox, how do you block the
user from making changes to the text?
 
One you have displayed something in a textBox, how do you block the
user from making changes to the text?

I cracked that one.

Re textBoxes:

I am left with this question: Is it possible to have a margin on the
left hand side, or on both sides, so the text doesn't come right up to
the side(s), which doesn't look so good.
 
Back
Top