私はよくVBとごっちゃになってAdditemとか、Removeitemとかやってしまいます。
//---------------------------------------------------------------------------
// Unit1.cpp
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//リストボックスに項目追加
int i;
for (i=0;i<20;i++){
ListBox1->Items->Add("ListBox->Items "+IntToStr(i));
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//リストボックス全クリア
ListBox1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
//リストボックスの最終項目削除
int i;
i = ListBox1->Items->Count - 1;
ListBox1->Items->Delete(i);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
//選択されている項目を表示
int i;
i = ListBox1->Items->Count;
for (i=0;i<ListBox1->Items->Count;i++){
if (ListBox1->Selected[i]){
ShowMessage(ListBox1->Items->Strings[i]);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
//リストボックスの内容を順次選択状態にする。
static int i = 0;
if (i>ListBox1->Items->Count-1){
i = 0;
}
if (ListBox1->MultiSelect == true){
ListBox1->Selected[i] = true;
}else{
ListBox1->ItemIndex = i;
}
i++;
}
DownLoad bcbtips032.lzh 4KB(BCB5)