Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
740
UltraFormattedTextEditor + SelectionStart
posted

Hi there,

I have a UltraFormattedTextEditor which is used for writing notes for the user.

I have to do this functionality when ever a user wants to add a quick note to the existing note (UltraFormattedTextEditor), when I click on another button, it place that quick note where my last cursor is placed on the ufteNoteText(UltraFormattedTextEditor)

Requirement:
if the cursor is placed BETWEEN existing words within a note
field and then a Quick Notes option is added to the note, then the quick note/s
will be added to the note on a new line after where the cursor is.
Any existing words that are in the note field after where the cursor was should
also be displayed on a new line after the quick note options have been added.

For example: if the following was entered in the note field and the cursor is
where the '*' is it would look like this before and after adding 3 quick notes:

BEFORE adding a Quick Note:
Test adding *a note in the note field

AFTER adding a Quick Note:
Testing adding
QUICK NOTE 1
QUICK NOTE 2
QUICK NOTE 3
 a note in the note field

Please find the below coding:

private void quickNotesTool1_OnInsertQuickNoteEvent(NetHealthBusinessObjects.BusinessDataObject.QuickNotes.QuicknotesCollectionBO selectedQuickNoteCollection)

{

string description = "", beforecursortext = "", aftercursortext ="";

if (!string.IsNullOrEmpty(ufteNoteText.Text))
{
if (ufteNoteText.IsInEditMode)
{
int selectStart = ufteNoteText.EditInfo.SelectionStart;
if (selectStart != 0)
{

int length = ufteNoteText.Text.Length;

int selectionStart = selectStart;
beforecursortext = ufteNoteText.Text.Substring(0, selectStart);
aftercursortext = ufteNoteText.Text.Substring(selectStart, ufteNoteText.Text.Length - selectStart);
}
}
}

(NOTE:  selectedQuickNoteCollection getting from the other window)


foreach (var item in selectedQuickNoteCollection.QuicknotesDetails)
{
description += Environment.NewLine + item.Description;
}


ufteNoteText.Text = beforecursortext + description + Environment.NewLine + aftercursortext;

}

BUT the issue is, when ever a new quick note is added (apart from the 1st quick note) the selectStart value is wrong which  adds 2 more indexes to it, where it will break it in the wrong position. When i see the quick watch on ufteNoteText.Text, i can see the"\r\n" is added in the text coz of the new line. is it because of that?

Please see the attached for the sample for steps which is happening now.

I need when ever a quick note added, where ever the cursor position is, break from there, and add a new line with the quick note and display the rest of the note after the quick note is added.

Let me know if you are not clear on the steps!!

PLS LET ME KNOW A SOLUTION CODE ASAP!

Thanks in advance!!

Parents Reply Children
No Data