604
社区成员




__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ListView1->RowSelect = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TListView *lv = (TListView *)Sender;
if (!lv) return;
TListItem *pItem = lv->GetItemAt(X, Y);
if (pItem)
{
int nCellLeft(0), nColIndex(0);
TPoint pt(X, Y);
TRect rct = pItem->DisplayRect(drSelectBounds);
for (int i=0; i<lv->Columns->Count; i++)
{
rct.Left = nCellLeft;
rct.Right = nCellLeft + lv->Columns->Items[i]->Width;
if (PtInRect(rct, pt))
{
nColIndex = i + 1;
break;
}
nCellLeft += lv->Columns->Items[i]->Width;
}
ShowMessage(String().sprintf("点击了第 %d 行,第 %d 列", pItem->Index + 1, nColIndex));
}
}