-
January 26th, 2012, 03:09 PM
#1
how to prevent changing selection in a list box
How can I prevent changing selection in a list box (CListBox).
When user changes the selection I need to verify current data. If the data is not valid I need to disallow changing the selection. I handled ON_LBN_SELCHANGE but it doesn't give me much control. I am looking for something like SELECTION_CHANGING where I can cancel the change if my data is not valid. Is this possible in a list box?
-
January 26th, 2012, 03:50 PM
#2
Re: how to prevent changing selection in a list box
List box is very old control... it wasn't designed for such "complicated" logic...
So you could either implement some type of UNDO to re-select the previously selected item if the conditions failed or move from list box to some other control like ListView control.
Victor Nijegorodov
-
January 26th, 2012, 03:58 PM
#3
Re: how to prevent changing selection in a list box
Just keep track of the current selection. If the user attempts a change you don't like, just set it back to what it was.
Alternately you could use PreTranslateMessage to intercept the message before the list box gets it and only pass it on to the list box if the selection is valid.
-
January 29th, 2012, 02:30 PM
#4
Re: how to prevent changing selection in a list box
Or just disable the control until the routine gets to finish. This will reliably prevent the control from any change.
Best regards,
Igor
-
February 22nd, 2012, 04:38 AM
#5
Re: how to prevent changing selection in a list box
u can check it in pretranslate method... if the message is LBN_SELCHANGE then u can do checking whatever u want ... if data varifies ur request then make it pass otherwise return true from there...
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
|