Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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[^]
 
Share this answer
 
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:
C++
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().
 
Share this answer
 
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.
 
Share this answer
 
Comments
chandanadhikari 6-Dec-12 8:23am    
hiplease vote for the solutions if you found them useful. :)
BillW33 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.
fd9750 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900