LoginSignup
0
1

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > TComboBoxの選択解除 > BackSpace入力時に解除する / Ctrl-Delete入力時に解除する

Last updated at Posted at 2015-07-29
動作確認
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/26)

https://groups.google.com/forum/#!topic/borland.public.delphi.vcl.components.using/85snFfhvhTI
にある実装例

  • I often look for the backspace (#8) key in an OnKeyPress handler and set the ItemIndex to -1 if I see it.

backspaceでの実装例

void __fastcall TItem_options::ComboBox1KeyPress(TObject *Sender, System::WideChar &Key)

{
    // Backspaceキーによる選択解除

    TComboBox *cbPtr = (TComboBox *)Sender;

    if (Key == VK_BACK) {
        SendMessageA(cbPtr->Handle, CB_SHOWDROPDOWN, 0, 0); // Close ComboBox
        cbPtr->ItemIndex = -1; // deselect
    }
}

ItemIndex = -1にするだけではコンボボックスが開いたままとなり、閉じる時に再度選択されてしまう。

閉じる処理の参考 http://www.geocities.jp/asumaroyuumaro/program/tips/ComboBoxMessage.html



Ctrl-deleteで選択解除する場合
void __fastcall TItem_options::ComboBox1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)

{
    if (Shift.Contains(ssCtrl) && Key == VK_DELETE) {
        SendMessageA(ComboBox1->Handle, CB_SHOWDROPDOWN, 0, 0); // Close ComboBox
        ComboBox1->ItemIndex = -1; // deselect
    }
}

Ctrl-Deleteの参考 http://bcbjournal.org/forums/viewtopic.php?f=10&t=2587

Shift == ssCtrlではエラーがでた。Contains()を使う。

追記

(2017/12/26)

ItemIndex = -1にするだけではコンボボックスが開いたままとなり、閉じる時に再度選択されてしまう。

この状況が再現しなくなっている?

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1