• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 715
  • Last Modified:

Visual C++ - UpdateData(), keeping cursor at end of string

I need to add a CString variable to an edit box and then immediately have the cursor at the end of the string in the edit box. I have been using UpdateData(FALSE) to display the variable in the edit box but this places the cursor at the start of the string.

Please help.
  • 2
1 Solution
sjhlAuthor Commented:
Adjusted points to 80
Looks like CEdit is derived from CWnd, CWnd has a method called SetCaretPos() so since your edit control is using a CEdit object to store the text you should be able to do something like


See if that works for ya.
Vinayak KumbarSr Program ManagerCommented:

Do like this after inserting the string

m_ctrlEdit.SetSel(m_strEdit.GetLength()-2, m_strEdit.GetLength()-1, FALSE);

Here m_ctrlEdit is the member variable for the edit control of CEdit type.
Here m_strEdit is the member variable for the edit control of CString type.

Hope that solves ur prob.

sjhlAuthor Commented:
Exactly what I wanted.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now