|
-
February 17th, 2010, 06:21 PM
#1
Index was outside the bounds of the array
Hey all,
I am trying to put a text of textbox1 into richtextbox but apearently i am getting a error saying " Index was outside the bounds of the array."
The code i am using is very simple, here it is : "richTextBox1->Lines[0]=textBox1->Text;"
I wish to solve this error and know why i got it cause everything seems fine to me,
Thanks in advanced.
-
February 18th, 2010, 01:21 AM
#2
Re: Index was outside the bounds of the array
Array returned by Lines property is read-only. You can only assign the whole array to the Lines property:
richTextBox1->Lines = gcnew String^ [] { textBox1->Text };
-
February 18th, 2010, 11:14 AM
#3
Re: Index was outside the bounds of the array
i tried that and i got a error saying " a native array cannot contain this managed type"
for some reason i dont think this is the right way of doing it, isnt there any other ay to write to a line in a richtextbox?
Thanks in advanced
-
February 18th, 2010, 12:28 PM
#4
Re: Index was outside the bounds of the array
you have to use the SetValue method to change a particular line or a range of lines.
richTextBox1->Lines->SetValue(.....)
edit: mhmm... somehow it doesn't work either
Last edited by memeloo; February 18th, 2010 at 01:00 PM.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
February 18th, 2010, 12:57 PM
#5
Re: Index was outside the bounds of the array
-
February 18th, 2010, 01:01 PM
#6
Re: Index was outside the bounds of the array
I did what you said and i tried this for testing : "richTextBox1->Lines->SetValue("test",0);"
but nothing happens, the richtextbox just stays empty :S ?
Am i using the setvalue function incorrectly :S ?
-
February 18th, 2010, 01:30 PM
#7
Re: Index was outside the bounds of the array
I got it 
Code:
this->richTextBox1->Text =
"line1" + Environment::NewLine +
"line2" + Environment::NewLine +
"line3" + Environment::NewLine;
int iLine = 1;
String ^before = (String^)richTextBox1->Lines->GetValue(iLine);
int iFirstChar = richTextBox1->GetFirstCharIndexFromLine(iLine);
richTextBox1->Select(iFirstChar, before->Length);
richTextBox1->SelectedText = "it works!";
String ^after = (String^)richTextBox1->Lines->GetValue(iLine);
I'd suggest to change the topic of this thread to "How to change a line in a RichTextBox"
Last edited by memeloo; February 18th, 2010 at 01:40 PM.
Reason: added new topic suggestion; corrected a typo
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
February 18th, 2010, 01:36 PM
#8
Re: Index was outside the bounds of the array
Thanks it works but do you mind explaining the code a little bit ?
-
February 18th, 2010, 01:39 PM
#9
Re: Index was outside the bounds of the array
first try to find the methods and properties in the documentation RichTextBox and read about them and if you still have problems come back and we'll see
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
February 18th, 2010, 01:41 PM
#10
Re: Index was outside the bounds of the array
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|