How to send a CBN_SELCHANGE message when using CB_SETCURSEL?

后端 未结 3 362
醉酒成梦
醉酒成梦 2021-01-20 09:55

When using the CB_SETCURSEL message, the CBN_SELCHANGE message is not sent.

How to notify a control that the selection was changed

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-20 10:29

    You're not supposed to use CBN_SELCHANGE unless the change in selection was made by the user.

    You don't indicate what language you're using; it would make it easier to provide you with a workaround if you did so.

    In Delphi, where an OnChange() would be associated with the combobox, you just call the event method directly:

    // Send the CB_SETCURSEL message to the combobox
    PostMessage(ComboBox1.Handle, CB_SETCURSEL, Whatever, WhateverElse);
    
    // Directly call the OnChange() handler, which is the equivalent to CBN_SELCHANGE
    ComboBox1Change(nil);
    

提交回复
热议问题