Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ VisualStudio2010
Hi,
 
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
good
Please Sign up or sign in to vote.

Solution 1

hi
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:
 
editbox[^]
 
Dialog Data Exchange in MFC[^]
 
also search in MSDN for more related information on MFC Dialog based application programming:
MSDN[^]
  Permalink  
Rate this: bad
good
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().
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
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.
  Permalink  
Comments
chandanadhikari at 6-Dec-12 8:23am
   
hi
please vote for the solutions if you found them useful. :)
CIDev at 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 at 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)



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