I'm looking for the best way to sort lines of RichTextBox, I'm using this at moment:
public void SortLines(object sender, EventArgs e)
{
TextPointer pStart = TextInput.Document.ContentStart;
TextPointer pEnd = TextInput.Document.ContentEnd;
TextRange text = new TextRange(pStart, pEnd);
string[] lines = text.Text.Split('\n');
Array.Sort(lines);
text.Text = String.Join(String.Empty, lines);
}
Is there an best way to do this?
When I call it, the cursor is placed into first RichTextBox line, how do I to put it where it was before? I tried to set pStart/pEnd and CaretPositiom, but the properties are read only.
I hope this is clear. Thanks in advance.
An inelegant but practical solution; back and forth richtextbox to ListBox : In the properties on your listBox you click 'sorted'> true
[c#]
ListBox1.Items.AddRange(RichTextBox1.Lines);
for (int x = 0; (x
<= (ListBox1.Items.Count - 1)); x++) {
RichTextBox1.AppendText((ListBox1.Items(x).ToString.Environment.NewLine));
}
[VB.NET]
ListBox1.Items.AddRange(RichTextBox1.Lines)
For x As Integer = 0 To ListBox1.Items.Count - 1
RichTextBox1.AppendText(ListBox1.Items(x).ToString & Environment.NewLine)
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With