-
June 14th, 2005, 05:41 AM
#1
Lvn_itemchanging
Ok, this drives me nuts...
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.
Why?
-
June 14th, 2005, 06:02 AM
#2
Re: Lvn_itemchanging
Is it possible that the messagebox itself causes the item to lose focus?
Try writing debug messages to a text file instead! Just to make sure...
-
June 14th, 2005, 06:07 AM
#3
Re: Lvn_itemchanging
Hi zerver
Gotcha! If I do not use the MsgBox, I get there only once...
Ok, then I'll code a workaround.
Thank you very much!
-
July 26th, 2005, 03:39 AM
#4
Re: Lvn_itemchanging
Hi,
I have exactly the same problem than you please can you help me for the workaround
Regards
-
July 26th, 2005, 04:04 AM
#5
Re: Lvn_itemchanging
A possible solution would be
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.
Not genuine, but it works.
-
October 10th, 2012, 10:05 AM
#6
Re: Lvn_itemchanging
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.
void CCommentsTabDlg::OnItemchangingCmntsCommentList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if ( pNMListView->uChanged == LVIF_STATE &&
( pNMListView->uOldState == LVIS_FOCUSED ||
pNMListView->uOldState == LVIS_SELECTED ) &&
( m_nMode == MODE_ADD || m_nMode == MODE_UPDATE ) ) {
// Only show message once to prevent the message when focus and selection change.
if ( pNMListView->uOldState == LVIS_FOCUSED ) {
if ( m_nMode == MODE_ADD ) {
m_sUpdateAddMessage = "You cannot select another comment while adding.\n\nYou must finish adding first.";
}
else if ( m_nMode == MODE_UPDATE ) {
m_sUpdateAddMessage = "You cannot select another comment while updating.\n\nYou must finish updating first.";
}
PostMessage(WM_UPDATE_ADD_MESSAGE);
}
// Do not allow ItemChange
*pResult = -1;
}
else {
*pResult = 0;
}
}
2003 Thread: http://forums.codeguru.com/showthrea...N_ITEMCHANGING
-
October 10th, 2012, 10:22 AM
#7
Re: Lvn_itemchanging
Oliver hasn't visited this site for over 6 years.
-
October 10th, 2012, 10:24 AM
#8
Re: Lvn_itemchanging
That is not why I posted. I posted because I had the same problem that he did. I just wanted to clarify for anyone like me that finds this post.
-
October 10th, 2012, 11:00 AM
#9
Re: Lvn_itemchanging
Originally Posted by TroyKroening
That is not why I posted. I posted because I had the same problem that he did. I just wanted to clarify for anyone like me that finds this post.
Before posting anything you should first have read the Announcement: Before you post....
Victor Nijegorodov
-
October 10th, 2012, 11:07 AM
#10
Re: Lvn_itemchanging
Victor, I looked at the Announcement link that you posted. I read it fully and do not understand how it applies. Can you clarify?
-
October 10th, 2012, 11:17 AM
#11
Re: Lvn_itemchanging
Originally Posted by TroyKroening
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.
Victor Nijegorodov
-
October 10th, 2012, 11:29 AM
#12
Re: Lvn_itemchanging
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.
-
October 11th, 2012, 05:52 AM
#13
Re: Lvn_itemchanging
Nobody cares how it works as long as it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|