Board index » cppbuilder » To all TListView-Experts

To all TListView-Experts


2003-11-28 09:05:19 PM
cppbuilder27
Hello.
I need to do some changes in a bigger App, which uses a TListView in vsReport type. I have to perform some actions when I click with my mouse on a specific "cell".
Unfortunately, the TListView logic is focused to the items in the first column and there is no special Event like OnSelectCell from TStringGrid.
I can of couse do some calculation with the mouse coordinates, but there is one problem: There seems to exist no way to get the position of a TListView's horizontal scroller.
I hope there is a tricky way to get this information - please help me.
Many thanks in advance,
Andreas
 
 

Re:To all TListView-Experts

"Andreas S" < XXXX@XXXXX.COM >wrote:
Please wrap your lines when posting. Your editor may visually
wrap them but you need to enter a hard return at the end of
each line.
Quote
[...] I have to perform some actions when I click with my
mouse on a specific "cell". [...] I hope there is a tricky
way to get this information
Use GetHitTestInfoAt() in conjunction with GetItemAt() to get
the TListItem that has been clicked.
~ JD
 

Re:To all TListView-Experts

Quote
Please wrap your lines when posting. Your editor may visually
wrap them
Indeed ... sorry
Quote
Use GetHitTestInfoAt() in conjunction with GetItemAt() to get
Thanks, I'll try this.
Andreas
 

{smallsort}

Re:To all TListView-Experts

"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
 

Re:To all TListView-Experts

Andreas,
Quote
I need to do some changes in a bigger App, which uses a TListView
in vsReport type. I have to perform some actions when I click with
my mouse on a specific "cell".
You can use the LVM_SUBITEMHITTEST message to determine which "cell" was
clicked...
tinyurl.com/x65b
The message is documented here: tinyurl.com/x65f.
Good luck,
Damon (TeamB)