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:
Code:
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) &&
((pNMListView->uOldState&LVIS_FOCUSED)==LVIS_FOCUSED) &&
((pNMListView->uNewState&LVIS_FOCUSED)==0) )
{
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.
I found what appears to be you asking the same question again in 2003. I used your possible solution and built on it because it was losing the selection. See my example.
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...
Including Code
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.
That clarifies. I thought that you were talking about the post of mine that you quoted. I did not know that you were talking about my prior post with code.
Bookmarks