-
February 22nd, 2009, 11:12 PM
#1
CEdit Control Question
I have a main window which contains two CListCtrl controls and a button when pressed opens a new Dialog window in which the user can type or enter into a CEdit control. However what I want to do is to save the data contained in the CEdit control into one of the two CListCtrl. What I did was created the new dialog window using DoModal but when the function returns I try accessing the value contained in the CEdit control but nothing gets returned. I can only retrieve the value within the CEdit control in a OnOK handler of the new window.
Here is a sample code:
CUserInfo dlg;
int nResponse = dlg.DoModal();
if(nResponse == IDOK)
{
// Cannot get the values of the text field in the CEdit control here but only in the OK button handler of this new window.
// But I want to be able to get the values here in this function.
}
-
February 22nd, 2009, 11:25 PM
#2
Re: CEdit Control Question
Add a public variable attached to the CEdit control.
In the OnOK() or any other function that closes the dialog do an UpdateData().
Now in the main code after the DoModal you can access it like dlg.publicvariable.
-
February 23rd, 2009, 01:47 PM
#3
Re: CEdit Control Question
Originally Posted by _Superman_
Add a public variable attached to the CEdit control.
In the OnOK() or any other function that closes the dialog do an UpdateData().
Now in the main code after the DoModal you can access it like dlg.publicvariable.
Thanks for the reply. Can you tell me where do I add the public variable CEdit ? I understand what you mean as to where to place the UpdateData(TRUE); Also how does the application know that the CEdit (public) variable is associated with my IDC_EDIT1 ?
-
February 23rd, 2009, 01:56 PM
#4
Re: CEdit Control Question
Originally Posted by justmehere
Thanks for the reply. Can you tell me where do I add the public variable CEdit ? I understand what you mean as to where to place the UpdateData(TRUE); Also how does the application know that the CEdit (public) variable is associated with my IDC_EDIT1 ?
the application would know if you associate a member variable with your edit. you can either use class wizard to do this, or do it manually. if you decide to use class wizard, open your dialog that contains the edit and double click on the edit while pressing "Ctrl". this will bring up a dialog where you can choose your variable type. you can achieve the same behavior right-clicking the edit and selecting "Add variable..."
-
February 23rd, 2009, 02:26 PM
#5
Re: CEdit Control Question
Originally Posted by Alin
the application would know if you associate a member variable with your edit. you can either use class wizard to do this, or do it manually. if you decide to use class wizard, open your dialog that contains the edit and double click on the edit while pressing "Ctrl". this will bring up a dialog where you can choose your variable type. you can achieve the same behavior right-clicking the edit and selecting "Add variable..."
Many thanks Alin all is working. Appreciate both replies.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|