Forums
Forums are Read-Only. Use the new Support Center. To start a general discussion, use the General category when submitting your question.

Setting the caret position

Last post 1/30/2012 11:14 PM by Mandar Dhongade. 3 replies.
Sort Posts: Previous Next
  • David Maser

    Setting the caret position

    3/8/2010 6:25 PM
    • Not Ranked
    • Joined on 3/8/2010
    • Posts 2

    Hello and, first of all, DevExpress is awesome. It's really made my job easier. Now on to my question.

    I am converting a text editor I'd built a while back and using the XtraRichEdit component. The text editor allows users to select a point in the document and create a chapter that scrolls to that point. To set the chapter point I use Units.PixelsToDocuments and GetPositionFromPoint. With the old version of my editor (which use the basic WinForms rich text editor) I just set the caret position to the point and used the scrollToCaret() to send the user to the entry.

    I've been fiddling around with the .Document.CaretPosition but haven't found a way of actually setting the caretposition (which is an integer). I get the error Can not convert type int to ....DocumentPosition. I'm sure that there's a way of doing it but I can't find it. 

    Any help would be much appreciated. 

    Thanks in advance to all who take the time to read and answer this post.

    Dave

  • Brian (DevExpress)

    Re: Setting the caret position

    3/9/2010 4:03 AM
    • Top 50 Contributor
    • Joined on 4/23/2007
    • Posts 546

    Hello David,

    the Document.CaretPosition property requires a DevExpress.XtraRichEdit.API.Native.DocumentPosition object, representing the caret position, e.g.:

    DevExpress.XtraRichEdit.API.Native.DocumentPosition dp = 
    richEditControl.Document.CreatePosition(56); richEditControl.Document.CaretPosition = dp; richEditControl.ScrollToCaret();

    P.S. This is a peer-to-peer forum. For technical support, search our knowledge base at http://search.devexpress.com or contact our Support Team directly at http://www.devexpress.com/Support/Center/, to get a guaranteed reply within a business day.

     

    Regards, Brian.
    R&D, .NET Team, Developer Express Inc.
  • David Maser

    Re: Setting the caret position

    3/9/2010 10:38 AM
    • Not Ranked
    • Joined on 3/8/2010
    • Posts 2

    Thank you for your rapid response Brian. Your code was exactly what I needed. Now back to more coding Big Smile

  • Mandar Dhongade

    Re: Setting the caret position

    1/30/2012 11:14 PM
    • Not Ranked
    • Joined on 12/29/2011
    • Posts 1

     Hello,

    I have tried your suggested workaround...but it's not working for me... 

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.