Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting at top of richtextbox

Tags:

c#

richtextbox

Whats wrong with this code? Trying to get my text to insert at the beginning of the textbox rather than at the bottom.

private void execute_Click(object sender, EventArgs e){
  startFinshBox.Text = "Start Time: " + printTime()+"";
  startFinshBox.Text.Insert(0,printTime()+": Retrieving Results...\n");
}

But it will not insert the second line into the rtb. I have tried with startFinishBox.SelectionStart = 0 as well, and it made no difference. Am I missing something else?

Thanks, Psy

like image 301
Psytronic Avatar asked Nov 17 '25 07:11

Psytronic


1 Answers

startFinshBox.Text is a string, which is an immutable type in C#. string.Insert() will return the modified string as a result, but it your code you discard it. To make it work, you have to change the code to:

private void execute_Click(object sender, EventArgs e){
  startFinshBox.Text = "Start Time: " + printTime()+"";
  startFinshBox.Text = startFinshBox.Text.Insert(0,printTime()+": Retrieving Results...\n");
}
like image 114
Grzenio Avatar answered Nov 18 '25 20:11

Grzenio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!