CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Data Between 2 dialogs

    I have the main dialog with a find button. When pressed it opens a dialog (using DoModal()) with a list control that lists all records. I have an option to select edit. When this is done i want to move all the data back to the main screen. here is what i have done. Declared an instance of the class of the dialog i want to send it to with that instance i have set all the meber variables called CDialog::OnOk() and then called UpdataData(FALSE) but when it is done all the fields are still blank. Any help please?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Data Between 2 dialogs

    Write code in the main dialog that gets data from the second dialog after DoModal of the second dialog returns.

  3. #3
    Join Date
    Sep 1999
    Location
    France
    Posts
    393

    Re: Data Between 2 dialogs

    Hi,

    In OnOK of your second dialog call UpdateData(TRUE) instead of UpdateData(FALSE)

    Then in the main you will have the correct data of your second dialog.

    CMyDialog::OnOK(){
    UpdateData(TRUE);
    CDialog::OnOK();
    }

    I would even say that the call of UpdateData(TRUE) is automatically done in the CDialog::OnOK() function

  4. #4
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: Data Between 2 dialogs

    Thanks a lot for the replies. It is working great.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Data Between 2 dialogs

    Here's a sample that modifies a list item on a double click. It creates a list of items in an std::vector and puts the items in a virtual list control. When a user double clicks on the item, the underlying item object is passed to the dialog.

    Here's the code that displays the edit dialog on double click
    Code:
     
    void CListItem2DialogDlg::OnNMDblclkListctrl(NMHDR *pNMHDR,
    LRESULT *pResult)
    {
    int nItem = 0;
    CPoint pt;
    GetCursorPos(&pt);
     
    m_ctlList.ScreenToClient(&pt);
     
    if( INVALID_INDEX != (nItem = m_ctlList.HitTest( pt ) ) )
    {
    // Retrieve the CLVItemData object associated with this item
    	CLVItemData* pLVItemData 
    	 = reinterpret_cast<CLVItemData*>(m_ctlList.GetItemData( nItem ) );
     
    	if( NULL != pLVItemData )
    	{
    	 CLVItemEditDlg dlg( pLVItemData, this );
    	 if( IDOK == dlg.DoModal() )
    	 {
    		// Refresh this item
    		m_ctlList.RedrawItems( nItem, nItem );
    	 }
    	}
    }
    *pResult = 0;
    }
    The edit dialog code gets a pointer to the selected item. DoDialogExchange
    acts on the pLVItemdata directly (which simplifies the dialog code).
    Code:
    CLVItemEditDlg::CLVItemEditDlg(CLVItemData* pLVItemData, CWnd* pParent /*=NULL*/)
    : CDialog(CLVItemEditDlg::IDD, pParent) 
    , m_pLVItemData( pLVItemData )
    {
    ASSERT( NULL != m_pLVItemData );
    }
    void CLVItemEditDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_COLUMN1, m_pLVItemData->GetColumnOne());
    DDX_Text(pDX, IDC_COLUMN2, m_pLVItemData->GetColumnTwo());
    DDX_Text(pDX, IDC_COLUMN3, m_pLVItemData->GetColumnThree());
    }
    


    Arjay
    Attached Files Attached Files

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