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.
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
Re: Data Between 2 dialogs
Thanks a lot for the replies. It is working great.
1 Attachment(s)
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