LoginSignup
0
1

More than 5 years have passed since last update.

2016-01-18 c++ builder > TComboBox > Items[]変更時にItemIndexが変更されるのを回避する実装

Last updated at Posted at 2016-01-18
動作確認
C++ Builder XE4

TComboBoxにてItems[]を変更時、ItemIndexが-1に初期化されてしまう。
それを回避するため、以下のような関数を用意している。

void TItemsUpdator::setStringToTComboBoxItems(String str, TComboBox *cbPtr, bool withSpace)
{
    if (cbPtr == NULL) {
        return;
    }

    TStringList *slPtr = static_cast<TStringList *>( cbPtr->Items );

    int preIdx = cbPtr->ItemIndex;

    if (withSpace) {
        slPtr->StrictDelimiter = true;
        slPtr->Delimiter = L',';
        slPtr->DelimitedText = str;
    } else {
        slPtr->CommaText = str;
    }

    // Items[]変更時にItemIndexが-1に初期化されるので元々の値に戻す
    cbPtr->ItemIndex = preIdx;  
}

もっとシンプルな方法で同じことができないだろうか。

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