Click here to Skip to main content
11,921,898 members (68,972 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ VS2010

Very very new to visual c++ (3 days) and I have a question I do not seem to find an answer to.

How do you update the data in an individual edit control in a dialog application ?

"UpdateData" does the trick for all controls in the whole dialog but I need to update just one (edit) control while leaving the other ones well alone.

Any suggestion much appreciated.
Posted 6-Dec-12 0:22am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

you need to get a pointer of type CEdit and use it for data exchange to set the text or get the text from the edit control. Following links might help:


Dialog Data Exchange in MFC[^]

also search in MSDN for more related information on MFC Dialog based application programming:
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Each control of a dialog window has a unique ID (besides static controls). To access a control, you can pass this ID (see your dialog template in the resource view) to the GetDlgItem()[^] function. Once you have a pointer to this control, you can access member functions like SetWindwText() which will set the text for edit controls:
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_MYEDIT);
pEdit->SetWindwoText(_T("New text"));

Another option is to assign a member variable to the edit control. You can do this using the resource editor. Then use this variabale to change the text of your edit control (e.g. m_Edit1.SetWindowText(_T("New Text"))). This is the recommended way. If all controls that may be changed have such a member variable and use it for updating, you can omit the calls to UpdateData().
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


Thanks for the suggestions. Strangely enough I found the solution myself 1 minute after posting the question.

I have basically used the first method suggested by Jochen and that works just fine.
Good to know about the second one though, I can see that one coming in handy at a later date.

The first link suggested by Chandanadhikari is indeed correct, that is where I found the solution.

Thanks for the help.
chandanadhikari 6-Dec-12 8:23am
please vote for the solutions if you found them useful. :)
CIDev 6-Dec-12 16:58pm
You should not post a comment to a solution or an addition to your question as a "Solution". You can add a comment to a solution by pressing the "Have a Question or Comment?" button. I did not vote, but I thought you should know why this might be downvoted.
Filip Dossche 7-Dec-12 4:05am
OK, I´ll keep it in mind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 538
1 Dave Kreskowiak 260
2 Sergey Alexandrovich Kryukov 173
3 phil.o 170
4 RyanDev 134
0 OriginalGriff 7,036
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,286
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100