13,873
社区成员
发帖
与我相关
我的任务
分享 ListView_SetItemState(ListView1->Handle, 2, LVIS_SELECTED, LVIS_SELECTED);
::SetFocus(ListView1->Handle);ListView_EnsureVisible(ListView1->Handle, i, true);//---------------------------------------------------------------------------
void __fastcall TfrmTest::Button2Click(TObject *Sender)
{
FindDialog1->FindText = Edit1->Text;
FindDialog1->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TfrmTest::FindDialog1Find(TObject *Sender)
{
int nRow(-1), nCol(-1);
bool bFound(false);
for (int i = 0; i < ListView1->Items->Count; i++)
{
if (ListView1->Items->Item[i]->Caption != FindDialog1->FindText)
{
for (int j = 0; j < ListView1->Items->Item[i]->SubItems->Count; j++)
{
if (ListView1->Items->Item[i]->SubItems->Strings[j] == FindDialog1->FindText)
{
// 如果在某一行的Caption符合查找内容,就记录该行和列的索引
bFound = true;
nRow = i;
nCol = j + 1;
ListView1->Selected = ListView1->Items->Item[i];
}
}
if (bFound)
break;
}
else
{
// 如果在某一行的Caption符合查找内容,就记录该行和列的索引
bFound = true;
nRow = i;
nCol = 0;
ListView1->Selected = ListView1->Items->Item[i];
break;
}
}
if (bFound)
ShowMessage(String().sprintf("找到了! 位置在第%d行第%d列", nRow + 1, nCol + 1));
else
ShowMessage("没找到");
}