G
Gary Shell
I have a very ODD situation.
I have a RichTextBox and a button. In the button click event I have the
following:
me.richtextbox1.SelectedText="test"
Assuming I start with "aaaabbbbcccc" in the richtext box and I place the
caret between the a and b and hit the button. I get "aaaatestbbbbcccc" as
expected. Then I click between the b and the c and hit the button I get:
"testaaaatestbbbbcccc".
I added some watches on richtextbox1.SelectionStart and find that the first
time it is 5 as expected. But on the second button press it is zero! Also
the SelectionLength is zero on the second press even if I set the cursor
between the b and c and drag across the first three of the c's.
This all occurs in my actual application, so I created a simple form with
only these two elements and it works fine. So obviously something else is
interfering with this operation in my real application. I am at a loss as
to what!
In the real app the richtextbox is bound to a dataset, but I can't see why
that should cause this behavior. I don't see any other events firing that
might somehow screw up the SelectionStart like this. The Richtextbox is on
a tabpage (and so is the button), but again I see no reason why that should
have an effect.
Anybody else ever struggle with this?
Gary
I have a RichTextBox and a button. In the button click event I have the
following:
me.richtextbox1.SelectedText="test"
Assuming I start with "aaaabbbbcccc" in the richtext box and I place the
caret between the a and b and hit the button. I get "aaaatestbbbbcccc" as
expected. Then I click between the b and the c and hit the button I get:
"testaaaatestbbbbcccc".
I added some watches on richtextbox1.SelectionStart and find that the first
time it is 5 as expected. But on the second button press it is zero! Also
the SelectionLength is zero on the second press even if I set the cursor
between the b and c and drag across the first three of the c's.
This all occurs in my actual application, so I created a simple form with
only these two elements and it works fine. So obviously something else is
interfering with this operation in my real application. I am at a loss as
to what!
In the real app the richtextbox is bound to a dataset, but I can't see why
that should cause this behavior. I don't see any other events firing that
might somehow screw up the SelectionStart like this. The Richtextbox is on
a tabpage (and so is the button), but again I see no reason why that should
have an effect.
Anybody else ever struggle with this?
Gary