Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange RichTextBox.Select(0,x) problem

Status
Not open for further replies.

Kliot

Programmer
Jan 10, 2003
622
US
I have a databound form, one of the fields is a note field and I have it displayed in a RichTextBox. I want to be able to highlight certain words in the textbox.

If I use something like:

RTB.Select(5, 5)
RTB.selectionBackColor = Color.Yellow

everything works as expected, the 6th - llth characters are highlighted, when I move to the next record nothing is highlighted as expected.

The strange problem I have come across is if I use a start index of 0

RTB.Select(0, 5)
RTB.selectionBackColor = Color.Yellow

When I do this the first 5 characters are highlighted as expected but if I move to the next record or any other record from that point forward all the text is highlighted. The highlighting only goes away if I move to a blank note field.

Has anyone else come across this problem before? Any suggestions?

I have tried all methods of selecting the text and I get the same result, I even just created a new form with no other code and just the Rtb note field and I get the same result.

Thanks
 
Are you using this code in the textchanged event. If not try putting it there, you may have to clear the backcolor then use your code.
 
No, my code is in the bindingsource.positionChanged event. I can't use the textChanged event because it throws things off when the user it typing in the field. Clearing the background color and the event I am using is not the problem.

In fact my code works perfectly, what I am doing is when a user searches my databases note field I want to highlight the words that were searched much like yahoo does. It works like it should except when the search word is the first word in the note field and the start position of the selection is 0. When it's 0 the highlighting works as expected until you move to the next or previous record, then all the text in the note field is changed from that point on.

I have tried this a number of different ways with different databases and the result is consistant and not what is expected, I'm seriously thinking this is a bug.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top