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?
Re: how to prevent changing selection in a list box
List box is very old control... it wasn't designed for such "complicated" logic... :rolleyes:
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.
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.
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.
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...