Solved

How to move cursor to end of an edit control

Posted on 2000-03-15
6
781 Views
Last Modified: 2013-11-20
I am trying to move the cursor to the end of text in an edit control programmatically.

The user clicks a button outside of the edit control, (which causes the control to lose focus) and upon that action I am calling the edit control's SetFocus() function which places the cursor at the beginning of the control. How do I get it to place the cursor at the end of any text in the control?

Thanks.
0
Comment
Question by:rascal
6 Comments
 
LVL 2

Expert Comment

by:bbousquet
ID: 2621873
You might want to take a look at the following (works for a single line edit box - for multi-line, you'll have to tweak it):

CEdit m_yourEditControl;

int nLen = m_yourEditControl.LineLength();
m_yourEditControl.SetSel(nLen, nLen, TRUE);

[It should work - but I haven't actually compiled this - I'm writing it from memory]
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2622109
I think I found something in an MFC or SDK sample program that appeared to do what you are asking but I do not rmemmber for sure where. I think it was in a sample communications program that was maintaining a log of activity like Hyperterminal does. If you ask me to I will see if I can find it and if I find it I will post which sample it is as an answer.
0
 
LVL 1

Accepted Solution

by:
jianliuer earned 100 total points
ID: 2622120
CEdit* pEdit = ((CEdit*)GetDlgItem(IDC_YOUR_EDIT));
CString txt;
pEdit->GetWindowText(txt);
pEdit->SetSel(txt.GetLength(),txt.GetLength(),TRUE);

Good Luck!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:rascal
ID: 2622127
Thank you. bbousquet I would also like to give you points but there does not appear to be a way???? Please let me know how and I will give you 100 pts as well.

Thanks to all.
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2622145
Hi,

Well, I doubt on that. But I have not checked it. If it works it is fine. Otherwise do the following thing.

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.

VinExpert
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2622147
Just create a new question in this category and label it 'points for bbousquet'. i'll answer it and you'll be able to give me the points too.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 124
Creating Labels and Frequency list style reports in SAS code 9 92
List out all word 7 259
Sed question 2 68
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now