I've got a listview where the user may select an item from. In response to the item selection, controls on the dialog are set to item-specific values. If an item was previously selected, the entered data will be validated and stored if it is valid. If the data is invalid, an error box is displayed and the original list-control selection is restored.
The LVN_ITEMCHANGING handler is just like this:
void CMyDlg::OnItemChangingLC(NMHDR* pNMHDR, LRESULT* pResult)
NM_LISTVIEW* pNMListView =reinterpret_cast<NM_LISTVIEW*>(pNMHDR);
// Allow item change by default.
*pResult = static_cast<LRESULT>(FALSE);
// If an item loses focus.
if ( ((pNMListView->uChanged&LVIF_STATE) == LVIF_STATE) &&
AfxMessageBox(_T("NO NO NO!"));
// Prevent the change.
*pResult = static_cast<LRESULT>(TRUE);
But what should I say: The damned Msgbox will be hit twice with the same **** parameters of pNMListView: The same iItem, the same uChanged, the same uOldState, the same uNewState.
1) add a string member variable to the dialog, e.g. m_sError
2) store the change deny message in the member variable instead of displaying it in OnItemChangingLC
3) In OnItemChangingLC, *post* a user-defined message to your dialog and still return TRUE.
4) Handle the user-defined message in your dialog class and display the error text stored in the member variable.
Victor, I looked at the Announcement link that you posted. I read it fully and do not understand how it applies. Can you clarify?
You seem to be a writer, not a reader...
If you include listings within your messages, please use the # button or code tags from within the message editors. This will format your code using a non-proportional font and it will preserve spacing. Most importantly, will make your code easier to read.