 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andreas S Guest
|
Posted: Fri Nov 28, 2003 1:05 pm Post subject: To all TListView-Experts |
|
|
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
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri Nov 28, 2003 2:01 pm Post subject: Re: To all TListView-Experts |
|
|
"Andreas S" <nachtvogel (AT) web (DOT) de> 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
|
|
| Back to top |
|
 |
Andreas S Guest
|
Posted: Fri Nov 28, 2003 2:44 pm Post subject: 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
|
|
| Back to top |
|
 |
Andreas S Guest
|
Posted: Fri Nov 28, 2003 3:09 pm Post subject: Negative |
|
|
Sorry but GetItemAt() gives me NULL, when
clicking beyond the first column and
GetHitTestInfoAt provides no exact
information ("right client area").
I need the Information in which (logical)
column and row I clicked. And I need to
know the scrollers position.
Any idea?
Andreas
|
|
| Back to top |
|
 |
Mark Jacobs Guest
|
Posted: Fri Nov 28, 2003 4:50 pm Post subject: Re: Negative |
|
|
Have you ensured that the "highlight entire row" property
(ListView1->RowSelect=true;) of the vsreport style listview has been set to
true? If not, you may well get NULL from GetItemAt when clicking beyond the
first column.
--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
[email]markj (AT) criticalremovethisspuriousantispamstuff (DOT) co.uk[/email]
"Andreas S" <nachtvogel (AT) web (DOT) de> wrote
| Quote: |
Sorry but GetItemAt() gives me NULL, when
clicking beyond the first column and
GetHitTestInfoAt provides no exact
information ("right client area").
I need the Information in which (logical)
column and row I clicked. And I need to
know the scrollers position.
Any idea?
Andreas
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Nov 28, 2003 11:04 pm Post subject: Re: Negative |
|
|
"Andreas S" <nachtvogel (AT) web (DOT) de> wrote
| Quote: | Sorry but GetItemAt() gives me NULL, when clicking
beyond the first column
|
GetItemAt() will only work for subcolumns when the RowSelect property is set
to true.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Nov 29, 2003 12:04 am Post subject: Re: To all TListView-Experts |
|
|
"Andreas S" <nachtvogel (AT) web (DOT) de> wrote
| 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
|
|
| Back to top |
|
 |
Damon Chandler (TeamB) Guest
|
Posted: Mon Dec 01, 2003 6:20 am Post subject: 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...
http://tinyurl.com/x65b
The message is documented here: http://tinyurl.com/x65f.
Good luck,
Damon (TeamB)
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|