CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Posts
    515

    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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  5. #5
    Join Date
    Feb 2012
    Posts
    1

    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
  •  





Click Here to Expand Forum to Full Width

Featured