CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2007
    Posts
    96

    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.
    }

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Smile 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.

  3. #3
    Join Date
    Oct 2007
    Posts
    96

    Re: CEdit Control Question

    Quote Originally Posted by _Superman_ View Post
    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 ?

  4. #4
    Join Date
    Feb 2002
    Posts
    3,788

    Re: CEdit Control Question

    Quote Originally Posted by justmehere View Post
    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..."

  5. #5
    Join Date
    Oct 2007
    Posts
    96

    Re: CEdit Control Question

    Quote Originally Posted by Alin View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured