Mapping for edit box is not working. - Programmer

This is a discussion on Mapping for edit box is not working. - Programmer ; Hi all, I have a problem with AFX_DATA_MAP if I use it on edit box. It works fine for picture. I created a few edit boxes, such as first_name, last_name and etc. I used to resource wizard to create the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Mapping for edit box is not working.

  1. Mapping for edit box is not working.

    Hi all,

    I have a problem with AFX_DATA_MAP if I use it on edit box. It works
    fine for picture.

    I created a few edit boxes, such as first_name, last_name and etc. I
    used to resource wizard to create the mapping:

    first_name => m_first_name
    last_name => m_last_name


    The wizard created these data in my header file:

    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(UPDATE_EMPLOYEE_DLG)
    DDX_Text(pDX, IDC_FIRST_NAME, m_first_name);
    DDX_Text(DDX, IDC_LAST_NAME, m_last_name);
    //}}AFX_DATA_MAP

    In implementation file:

    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(ADD_EMPLOYEE_RECORD_DLG)
    DDX_Control(pDX, IDC_FIRST_NAME, m_first_name);
    DDX_Text(pDX, IDC_LAST_NAME, m_last_name);
    //}}AFX_DATA_MAP

    When I run my program, I entered some values into the two fields, I
    set a break before in one of my dialog member functions, I noticed
    that the m_first_name and m_last_name variables were NULL. Here is
    what I had found in my program. If I made a change in dialog
    constructor, the mapping works. Outside the dialog constructor, the
    mapping does not work at all. Does anyone have any ideas to my
    problem? If so, please let me know. Thanks.

    -HS Phuah

  2. Re: Mapping for edit box is not working.

    If you are using CEdit with DDX_Control, remember that in the constructor of
    the dialog none of the controls have been created yet!

    If you are using CString with DDX_Text, you can just set your edit to
    whatever value you want to display in the edit control within the
    constructor.

    class CMyDlg : public CDialog
    {
    .......
    private:
    CString m_FirstName;
    CEdit m_FirstNameCtrl;
    };

    CMyDlg::CMyDlg(...)
    :CDialog(...)
    {
    m_FirstNameData = "MyFirst";
    }

    void CMyDlg:oDataExchange(...)
    {
    DDX_Control(IDC_FIRST,m_FirstNameCtrl); //this actually maps a
    control object to the edit control, this object becomes avaliable after call
    to CDialog::OnInitDialog()
    DDX_Text(IDC_FIRST,m_FirstName); //this gets and sets data of the
    edit control
    }

    void CMyDlg::OnInitDialog()
    {
    CDialog::OnInitDialog()

    m_FistNameCtrl.SetWindowText("Text");
    }

    void CMyDlg::OnOK()
    {
    UpdateData(true);
    m_FirstName has the value that was in the edit when they pressed ok

    m_FirstNameCtrl.GetWindowText(Text); // this will also do the same thing

    CDialog::OnOK();
    }

    "Hon Seng Phuah" wrote in message
    news:3898598f.0311232240.45f23745@posting.google.c om...
    > Hi all,
    >
    > I have a problem with AFX_DATA_MAP if I use it on edit box. It works
    > fine for picture.
    >
    > I created a few edit boxes, such as first_name, last_name and etc. I
    > used to resource wizard to create the mapping:
    >
    > first_name => m_first_name
    > last_name => m_last_name
    >
    >
    > The wizard created these data in my header file:
    >
    > CDialog:oDataExchange(pDX);
    > //{{AFX_DATA_MAP(UPDATE_EMPLOYEE_DLG)
    > DDX_Text(pDX, IDC_FIRST_NAME, m_first_name);
    > DDX_Text(DDX, IDC_LAST_NAME, m_last_name);
    > //}}AFX_DATA_MAP
    >
    > In implementation file:
    >
    > CDialog:oDataExchange(pDX);
    > //{{AFX_DATA_MAP(ADD_EMPLOYEE_RECORD_DLG)
    > DDX_Control(pDX, IDC_FIRST_NAME, m_first_name);
    > DDX_Text(pDX, IDC_LAST_NAME, m_last_name);
    > //}}AFX_DATA_MAP
    >
    > When I run my program, I entered some values into the two fields, I
    > set a break before in one of my dialog member functions, I noticed
    > that the m_first_name and m_last_name variables were NULL. Here is
    > what I had found in my program. If I made a change in dialog
    > constructor, the mapping works. Outside the dialog constructor, the
    > mapping does not work at all. Does anyone have any ideas to my
    > problem? If so, please let me know. Thanks.
    >
    > -HS Phuah




+ Reply to Thread