如何在TListBox中获取所选项目并使用Borland C ++ Builder 6在第二个TListBox中添加项目。
答案 0 :(得分:2)
正如David在他的回答中所说,你需要使用Selected属性。
这是我过去在几个项目中使用的一个简单函数。
void __fastcall TSelectForm::CopySelectedList(TListBox *SrcLB, TListBox *DestLB, bool ClearDest)
{
DestLB->Items->BeginUpdate();
if (ClearDest) DestLB->Clear();
// copy selected items from source listbox
for (int Index = 0; Index < SrcLB->Count; ++Index)
{
if (SrcLB->Selected[Index])
{
DestLB->Items->Add(SrcLB->Items->Strings[Index]);
} // end if
} // end for
DestLB->Items->EndUpdate();
} // end CopySelectedList
答案 1 :(得分:1)
您需要迭代Selected []属性。如果选择[i] == true,则选择Items [i]。