Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DRAG AND DROP question. 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
428
IT
two question:

- During the drag and drop operation i need to use a typical little arrow icon on cursor
- when i move the cursor on msflexgrid i need to higlight the cell of destination, or if is possible focus the destination cell with the little rectangle. (In this case the user know the destination cell of msfkexgrid)
 
 https://files.engineering.com/getfile.aspx?folder=b3dee804-fee5-43bd-8627-17cef0ad0667&file=ListBox_2_MSFlexGrid_DRAG_DROP.zip
This is a minor modification of your code to point you in the right direction (this version is somewhat inefficient, for example). It assumes you add an ImageList control with three icons in it to the form - a base drag icon (same as the one you assigned to the listbox), a 'not allowed' icon, and a 'you can drop here' icon. The choice of themn is up top you.

Code:
Option Explicit

Public CurrentHighlightMode As Long

Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
        lstItems.DragIcon = ImageList1.ListImages(2).ExtractIcon
End Sub

Private Sub Form_Load()
    
    [COLOR=green]' fill the list box with some text[/color]
    Call Load_Listbox
    
End Sub

Private Sub lstItems_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    lstItems.DragIcon = ImageList1.ListImages(1).ExtractIcon
End Sub

Private Sub lstItems_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    [COLOR=green]' test for left mouse button to start drag[/color]
    If Button = vbLeftButton Then
        CurrentHighlightMode = mfgData.HighLight
        lstItems.Drag vbBeginDrag
    End If
    
End Sub

Private Sub mfgData_DragDrop(Source As Control, X As Single, Y As Single)
    
    [COLOR=green]' test for list box drag source[/color]
    If Source.Name <> "lstItems" Then Exit Sub
    
    [COLOR=green ]' use the flex grid mouse tracking to decide which cell to
    ' copy the text to...or use a specific row and/or column if
    ' you need to limit the copy to a certain cell[/color]
    mfgData.TextMatrix(mfgData.MouseRow, mfgData.MouseCol) = Source.Text
    
    mfgData.HighLight = CurrentHighlightMode
    
End Sub

Private Sub Load_Listbox()
    
    [COLOR=green]' load the list box[/color]
    lstItems.AddItem "Red"
    lstItems.AddItem "Green"
    lstItems.AddItem "Blue"
    lstItems.AddItem "Yellow"
    lstItems.AddItem "Pink"
    
    
    
End Sub

Private Sub mfgData_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    mfgData.SetFocus
    lstItems.DragIcon = ImageList1.ListImages(3).ExtractIcon
    With mfgData
        .HighLight = flexHighlightWithFocus
        .Col = .MouseCol
        .Row = .MouseRow
    End With
    
End Sub

 
Bro....
Wow your code work like a charm
Tks!!!!

Great, also the clear explain.

but to maintain the standard cursor of mouse for all operation, drag, drop and error?
 
>maintain the standard cursor of mouse for all operation, drag, drop and error?

Just preload the ImageList with the cursors or icons you need. Image 1 = initiate drag icon/cursor, Image 2 = no drop allowed here icon/cursor, Image 3 = drop allowed icon/cursor

 
tks bro, for explain and suggestion!
 
sal21, would be nice if you mark helpful post(s) with a Star.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top