Help! Insert Text Into Rich Text Box
I can't seem to figure out how to take text read from a listbox and insert it into a richtextbox.
I thought this would work:
Dim
insertTextAsString = ListBox1.SelectedItem.ToString
myPos = RichTextBox1.SelectionStart
RichTextBox1.Text.Insert(myPos, insertText)
What am I doing wrong?
Help!!!!
Thanks!
[546 byte] By [
S.Rains] at [2007-12-24]
Not really knowing what you are trying to accomplish, how about something as simple as:
RichTextBox1.Text = ListBox1.SelectedItem.ToString
?
-Olice
Thanks for the quick response!
I should have explained better... My bad...
I am populating RichTextBox1 with what amounts to a tab-delimited text file that I am reading from my UNIX server:
Dim
file As New System.IO.StreamReader(editFile)words = file.ReadToEnd()
file.Close()
Kill(editFile)
Me.Hide()Dim frm15 As New Form15frm15.RichTextBox1.Text = words
frm15.TextBox9.Text = limFile
frm15.Activate()
frm15.Show()
Once that is complete (this works to this point), I want the user to have the ability to edit the text in the RichTextBox manually (which also works) or insert text at the current location within the file from the ListBox (this is where it no longer works as expected):
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim textSelected As String = "Valid"Dim myPos As IntegerTryDim listOption As String = ListBox1.SelectedItem.ToStringCatch ex As ExceptiontextSelected = "Error"
End TrySelect Case textSelectedCase "Valid"Dim insertText As String = ListBox1.SelectedItem.ToStringmyPos = RichTextBox1.SelectionStart
RichTextBox1.Text.Insert(myPos, insertText)
ListBox1.ClearSelected()
Case "Error"MessageBox.Show(" " & vbCrLf & "No text selected!" & vbCrLf, "Error!!!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End SelectEnd SubI know the sub is working (or at least accessed) because my listbox selection is cleared, but nothing is actually inserted into the richtextbox... Help!?!?
Please, this code was very helpful. And I want to thank you.
However, i want to request from you to send to me how to connect to Microsoft Access Database through VB codes. I also need your help on how to write backups in Visual basic. Your contribution and help will go a long way to enhancing my abilities in VB.
Please I need your help. My email address is egoehseth@yahoo.com
Thank you very much. And I know that you will send it to me. God bless you
Thanks! I'm apparently not bright enough to read 
This worked:
RichTextBox1.SelectedText = insertText
Instead of:
RichTextBox1.Text.Insert(myPos, insertText)
Amazing how the obvious evades us in the time of need...
Thanks!