Can I set the cursor position in an EditControl

I see I can get the CursorIndex in EditControl but I don't see a way to set the position in an EditControl - is it possible?

9 Replies

DR Durga Rajan Syncfusion Team February 22, 2018 12:00 PM UTC

Hi Mike,  

Thanks for contacting Syncfusion support.  

SelectLines method in EditControl is used select single line or multiline text with in the specified range. We can achieve your requirement “How to move the cursor to specified index” by passing same index value for StartLine & EndLine and StartIndex & EndIndex. We have prepared work-around sample to meet your requirement. In this sample we have move the cursor to 5th index of the 3rd line. Please find the code example for the same.  

Code Example :  

editControl.SelectLines(3, 3, 5, 5); 

  
Please get back to us if you are facing any issues with the provided sample.  

Regards,  
Durga S.   



MA Mike Anderson February 26, 2018 08:59 PM UTC

This was very helpful, thank you for your excellent support!


DR Durga Rajan Syncfusion Team February 27, 2018 06:19 AM UTC

Hi Mike, 

Thanks for the update. 

Please let us know if you need any further assistance on this. 

Regards, 
Durga S. 



MA Mike Anderson February 27, 2018 04:02 PM UTC

I do have a follow up question now that you mention it. Some basic controls, like TextBox, support accessing the absolute cursor position. They report position including EOL characters. So, the position will reflect the EOL sequence ( CR LF, or LF) depending on the file type.

I would like to know if there is a similar method for accessing the absolute cursor position within the text in an EditControl. It looks like CursorIndex reports the position within a line not within the entire text stream. I suppose I can calculate absolute position given LineNumber and CursorIindex and EOL sequence, just wondering if there is an easier way?


DR Durga Rajan Syncfusion Team February 28, 2018 06:08 PM UTC

Hi Mike, 

We regret to inform you that there is no default way to the access the position of cursor. As mentioned earlier, we have to use the SelectLines method of EditControl to set the cursor index.  

Regards, 
Durga S. 



MA Mike Anderson February 28, 2018 08:09 PM UTC

These questions are related to the issue of preserving the newline sequence in an EditControl. Some text streams might use CR, some LF, some CRLF. I want to preserve the newline chars within a given EditControl. Is there a way to set the newline sequence for an EditControl?


DR Durga Rajan Syncfusion Team March 1, 2018 12:53 PM UTC

Hi Mike, 

We can create to new line with the help of new line characters "\r\n" or “\n” or Environment.NewLine static property of Environment class. We have prepared sample which tries to meet your requirement.  In this sample, we have added new line and set cursor to the newly added line. Please download the sample for the same from below location, 

Code Snippets: 

"Click the button to set cursor index" + "\r\n" 


If we have misunderstood your query please get back to us with more details. This would help us to provide solution at earliest. 

Regards, 
Durga S. 



MA Mike Anderson March 1, 2018 11:19 PM UTC

Thanks for the sample. You will note, when the editControl is first loaded it has a mixture of "\r\n" and "\n" in the text, just as you would expect from your initialization of the literal string. And when you hit the button it adds "\r\n" to the end of the text, just as you would expect. But when you put the cursor somewhere in the text and hit Enter all the newline sequences get changed to "\r\n". I want to place the cursor somewhere, hit Enter and preserve the newline sequences already in place in the text. I think I have to capture the Enter key, and for that cursor location stick in the appropriate newline sequence (based on what's already in the text - a newline sequence typically won't change in a text stream). Problem is, I can't reliably find the cursor position to stick the newline sequence. Although I think I found a workaround by using the current line and the cursorindex to calculate where the cursor position is. A bit of a mess, but doable.


DR Durga Rajan Syncfusion Team March 2, 2018 06:05 PM UTC

Hi Mike, 

We regret to inform you that, we can set cursor to specific location only by the given work-around for now. But if you could briefly describe how you want us to have the feature in our control, based on the feasibility, we will consider your requirement as feature request. 

Regards, 
Durga S. 


Loader.
Up arrow icon