Drumma777
06-04-2002, 02:03 PM
All I want to do is prevent the user from being able to drag the icons all over the ListView control. Is there a way to totally lock all movement on the icons in Large Icon view but still allow the user to just select the icons?
Can anyone help??
Thanks! :p
Rick.
sl8rz
06-05-2002, 11:42 AM
I've used ListViews a few times but have never used icons in them. Since nobody has replied to your post, as of yet, I'll see if I can come up with something for you.
Let me play around with it a bit.
sl8rz
Drumma777
06-05-2002, 12:08 PM
The 2 attached files shows how the listview in large icon mode should look and how it looks after dragging an icon to far to the left. On the Mouse_Down and Up events I do the following...
Mouse_Down...
lvwUnitApps.Arrange = lvwAutoTop
lvwUnitApps.Sorted = True
lvwUnitApps.Refresh
Mouse_Up...
lvwUnitApps.Arrange = lvwAutoTop
lvwUnitApps.Sorted = True
Call ShowScrollBar(lvwUnitApps.hwnd, SB_BOTH, False)
lvwUnitApps.SelectedItem.EnsureVisible
Form_Load...
With lvwUnitApps
Set itmX = .ListItems.Add(, , "ICP9000", 1)
itmX.SubItems(1) = "1"
Set itmX = .ListItems.Add(, , "IPE2500A", 2)
itmX.SubItems(1) = "2"
Set itmX = .ListItems.Add(, , "IRC3000", 3)
itmX.SubItems(1) = "3"
Set itmX = .ListItems.Add(, , "ITD3000A", 4)
itmX.SubItems(1) = "4"
Set itmX = .ListItems.Add(, , "ITI6000", 5)
itmX.SubItems(1) = "5"
Set itmX = .ListItems.Add(, , "ITR2000A", 6)
itmX.SubItems(1) = "6"
'.ListItems(2).Ghosted = True
.ListItems(3).Ghosted = True
'.ListItems(4).Ghosted = True
.ListItems(5).Ghosted = True
'.ListItems(6).Ghosted = True
.View = lvwIcon
End With
lvwUnitApps.SortKey = 1
lvwUnitApps.Sorted = True
lvwUnitApps.SelectedItem.EnsureVisible
Something really wierd is going on with this control because if I drag an icon to the right or bottom past the ListView extents it auto-scrolls but it moves them back to where they're supposed to be. Moving to the left and/or top causes them to be placed toward the bottom right. :( Frustrating. I just want to lock 'em or figure out this "bug".
Thanks! :D
Rick.
sl8rz
06-05-2002, 12:30 PM
I didn't run your code but I did notice that there is an "Arrange" property for the ListView. In this property there are three choices -- lvwNone, lvwAutoLeft, lvwAutoTop. So it seems that the top and left areas are arranged differently than the right and bottom sides.
Perhaps trying these different Arrange settings can help.
Also, I thought that you may be able to trigger an auto arrange event when the control loses focus so that any rearranging made by the user would basically be undone (occuring in the ListView1_LostFocus() sub routine).
Hope that helps...sorry I don't have more for you.
sl8rz
Drumma777
06-20-2002, 12:06 PM
I set up a "mouse trap" on the mouse down event in the listview control. I use the Windows API ClipCursor to create a tiny rectangle area (mouse trap) in the listview that only allows the mouse to move in that rectangle. So if the user tries to drag an icon it only allows the icon to move a tiny bit and it makes it feel like the icon is stuck to the screen! I was very pleased. ;)
Here's the module with the mouse trap (download and hacked by me) and the code I use to call it is here below.
'''MOUSE_DOWN EVENT
Private Sub lstvArchives_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim myPoint As POINTAPI
Call GetCursorPos(myPoint)
If Button <> 2 Then
Call EnableTrap(myPoint.X, myPoint.Y, 5, 5)
End If
End Sub
'''MOUSE_UP EVENT
Private Sub lstvArchives_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call DisableTrap
End Sub
Rick Monyer
sl8rz
06-20-2002, 12:19 PM
Excellent solution!
You may want to check in this forum periodically and see if there are others with similar predicaments.
Banjo
06-20-2002, 02:10 PM
Very nice. Its not quite perfect as the it seems to suggest that that the item is locked in place rather than just immovable.
Certainly that is a small quibble and this is the best solution to I have seen to a problem that has generated several questions here before.
If you don't mind I'm going to post this in the Code Library as others will be helped by this. And its quite neat :)
klincecum
08-25-2004, 02:53 AM
I know this is old, but thank you. This does exactly what I need.
Kevin