[.net] How to give line number in a textBox?

Started by
6 comments, last by chrisliando 16 years, 2 months ago
1. I want to generate some kind of a log file using a multiline textBox and I have to give line number to it so that it is clear for user to know the detailed events. How to do that? 2. Everytime there is an event occured, I want to add a new line in the textBox. How to do that? I've tried the textBox->AppendText but it cannot create a new line, it places the appended text next to the last text. How to solve this? Thank you very much.. [Edited by - chrisliando on February 11, 2008 12:56:39 AM]
Advertisement
For every line inserted, prepend a padded line number.
If that's ugly, consider using some other control, like a multi-column list control.

To make it is hell. To fail is divine.

How to do this?
"For every line inserted, prepend a padded line number."


Thank you very much..
i = 1
for each line
line = i++ + line
Quote:Original post by chrisliando
2. Everytime there is an event occured, I want to add a new line in the textBox. How to do that? I've tried the textBox->AppendText but it cannot create a new line, it places the appended text next to the last text.

If you're not including "\r\n" before the string to be appended, then you should be. For reasons I've never fully understood, a single '\n' won't do it, the carriage return is necessary.
So how to combine "\r\n" with this:

i = 1
for each line
line = i++ + line

How?

And how to make the line number to be not selectable?

Thank you very much..
Are you asking for a source-code solution that you can copy/paste?
Or are you asking us to explain the concept of string concatenation?

i = 1for each line  line = i++ + line + "\r\n"



To make the line number not selectable, you'd be better off using a different approach all together, "like a multi-column list control" (to quote Zao).
No, everything is ok for me. If there is source code, then I will use it, if not it's also ok. I just confused.

But how to integrate the multi-column list control with the textBox?

Thank you.

This topic is closed to new replies.

Advertisement