Click here to Skip to main content
12,953,541 members (50,354 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 5-Dec-12 23:22pm
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
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,930

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
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