"Andreas S" <
XXXX@XXXXX.COM >wrote in message
Quote
I can of couse do some calculation with the mouse coordinates
That is what you will have to do.
Quote
There seems to exist no way to get the position of a TListView's
horizontal scroller.
You don't need to know that for what you ask. TListView has a TopItem
property that you can use to determine which item is visible at the top of
the list. You can then use the TListItem::DisplayRect() method to determine
the height of the item (all items will have the same height). With those
pieces of information, you can calculate the index of the item where the
mouse is. Then to determine the column, you just loop through the Columns
collection checking the widths of each column until you find which column
the mouse is within.
For example:
void __fastcall TForm1::ListView1MouseDown(TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y)
{
int Row, Column;
MouseToListItem(X, Y, Row, Column);
if( (Row != -1) && (Column != -1) )
// do something
}
void __fastcall TForm1::MouseToListItem(int X, int Y, int &Row, int
&Col)
{
Row = -1;
Col = -1;
RECT r;
TListItem *Item = ListView1->GetItemAt(X, Y);
if( Item )
r = Item->DisplayRect(drBounds);
else
{
Item = ListView1->TopItem;
if( Item )
{
r = Item->DisplayRect(drBounds);
if( Y < ((r.bottom - r.top) * (ListView1->VisibleRowCount +
1)) )
{
while( !PtInRect(&r, Point(X, Y)) )
{
Item = ListView1->GetNextItem(Item, sdBelow,
TItemStates());
if( !Item )
break;
r = Item->DisplayRect(drBounds);
}
}
}
}
if( Item )
{
Row = Item->Index;
for(int x = 0; x < ListView1->Columns->Count; ++x)
{
r.right = (r.left + ListView1->Column[x]->Width);
if( PtInRect(&r, Point(X, Y)) )
{
Col = x;
break;
}
r.left += ListView1->Column[x]->Width;
}
}
}
Gambit