如何同时获得ListView中数据所在的行和列
任意点击listview中显示的一个数据,如何能同时得到所点击数据所在的行值和列值呢?
非常感谢~~
[解决办法]
__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));
}
}