Objective Grid: Displaying a message box when closing a grid dialog

Article ID: 152
Last updated: 04 Jun, 2018
Article ID: 152
Last updated: 04 Jun, 2018
Revision: 3
Views: 1996
Posted: 11 Jan, 2001
by Meltreger B.
Updated: 04 Jun, 2018
by Meltreger B.

Problem


When I close the dialog via the system menu (X box in dialog title) I want to check whether the grid has been edited. Is it possible to display a message box when there are pending changes?


Cause



Action


Here is some sample code that shows you how to process the WM_CLOSE message of your parent dialog. m_wndGrid is the CGXRecordWnd (or CGXBrowserWnd) object which is displayed in the dialog.

void CRecordWndSampleDialog::OnClose()
{
m_wndGrid.TransferCurrentCell();

if (m_wndGrid.IsRecordDirty())
{

int nAction = AfxMessageBox(_T("Save changes?"), MB_YESNOCANCEL);

switch (nAction)
{
case IDYES:

m_wndGrid.Update();
break;
case IDNO:
m_wndGrid.CancelRecord();
break;
case IDCANCEL:
m_wndGrid.SetFocus();
return;
}
}

CDialog::OnClose();

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 152
Last updated: 04 Jun, 2018
Revision: 3
Views: 1996
Posted: 11 Jan, 2001 by Meltreger B.
Updated: 04 Jun, 2018 by Meltreger B.

Others in this category