|
-
Sep 28th, 2000, 02:03 AM
#1
Thread Starter
Hyperactive Member
I wish to use the listview in a similar as a form of grid.
The view is set to details, and fullrowselect is true etc, you get the idea.
Does anyone have any idea how to detect the column (listsubitem) that corresponds to a mous hit?
If the horizontal scroll bar not scrolled at all, it is
is easy enough work out the mouse to current column by working out where mouse.x falls by adding the column widths.
However, if the view is scrolled at all, this obviously fails.
So, the question is, do you know how to either get the ListSubItem for a mouse hit in details view, or, work out the amount of scroll/scroll position on a listview.
Thanks in advance.
Andy.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Sep 28th, 2000, 05:23 AM
#2
Frenzied Member
try this:
Code:
Option Explicit
Private Sub Form_Load()
Dim itmx As ListItem
Dim i As Integer
For i = 0 To 10
Set itmx = ListView1.ListItems.Add(, , "item " & i)
itmx.SubItems(1) = Time
itmx.SubItems(2) = Date
Next i
End Sub
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Debug.Print GetSubItem(x)
End Sub
Function GetSubItem(x As Single) As Integer
Dim ch As ColumnHeader
For Each ch In ListView1.ColumnHeaders
If x > ch.Left And x <= (ch.Width + ch.Left) Then
GetSubItem = ch.Index - 1
Exit For
End If
Next
End Function
-
Sep 28th, 2000, 07:41 PM
#3
Thread Starter
Hyperactive Member
Mark,
thanks for the reply, but as i said, this method
doesn't work if the table (number of columns) is bigger
than the listview size, and the listview is scrolled
right.
I'm figuring the only way i'm going to get this is to thru
a series of api calls, but think it's going to be painfull,
so i am open to any ideas ;-?
andy.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Sep 29th, 2000, 03:55 AM
#4
Frenzied Member
Sorry, I mis-read your posting.
try this:
Code:
Option Explicit
Dim LastX As Single 'retain the value of the mouse pointer X
Private Sub Form_Load()
Dim itmx As ListItem
Dim i As Integer
For i = 0 To 10
Set itmx = ListView1.ListItems.Add(, , "item " & i)
itmx.SubItems(1) = Time
itmx.SubItems(2) = Date
Next i
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Debug.Print GetSubItem(Item.Left)
End Sub
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
LastX = x
End Sub
Function GetSubItem(itemLeft As Single) As Integer
Dim ch As ColumnHeader
For Each ch In ListView1.ColumnHeaders
If LastX > ch.Left + itemLeft And LastX <= (ch.Width + ch.Left + itemLeft) Then
GetSubItem = ch.Index - 1
Exit For
End If
Next
End Function
-
Sep 29th, 2000, 04:41 AM
#5
Thread Starter
Hyperactive Member
sorry once again mark, this will not acheive what i need.
The listview is in Report view, and i need to know what
column has clicked (remember, i want to use the listview like a grid). ItemClick only fires when you click an
item, not a listsubitem (column). You can force the fire with fullrowselect, but this does tell you where your mouse really is.
The search continues...
Thanks
andy.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Sep 29th, 2000, 05:04 AM
#6
Frenzied Member
[qoute]You can force the fire with fullrowselect, but this does tell you where your mouse really is[/quote]
I was using fullrowselect and my bit of code calculates which column was clicked from the mouse pointer position.
what don't see what the problem is!
-
Sep 29th, 2000, 05:16 AM
#7
Thread Starter
Hyperactive Member
apoligies Mark, you were absolutley spot on.
Yes it does work, and you are now the man, in my book ;-)
Many Thanks.
Andy.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|