Results 1 to 3 of 3

Thread: Highlighting cells when dragging over

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Highlighting cells when dragging over

    I have a FlexGrid where you can click on a cell in Column 0 and drag and drop the contents of that cell onto another cell.

    This is part of the code in the Grid's Mousedown event:

    It resets all rows in the grid to white.
    It changes the colour of the cell that contains the data to be dragged.
    It changes the colour of all other cells in Column 0 that are available to be dropped on.
    This all works fine.


    Code:
    Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)
        
        Dim i As Integer, ThisRow as Integer, ThisCol As Byte
        
        ThisRow = MSFlexGrid1.MouseRow
        ThisCol = MSFlexGrid1.MouseCol
        
            With Me.MSFlexGrid1
                 
                    'Reset all rows to white
                    For i = 1 To .Rows - 1
                        Call HighlightRow(i, False)
                    Next
                    
                    'set the current cell
                    .Row = .MouseRow
                    .Col = .MouseCol
                
                    If .TextMatrix(ThisRow, ThisCol) <> "Not known" And .TextMatrix(ThisRow, ThisCol) <> "" And .TextMatrix(ThisRow, 7) = 0 Then
                    
                        .CellBackColor = &HFFFF80
                        .Drag vbBeginDrag 'start a drag operation.
                        strDragText = .Text 'store contents that will be dropped
                        DragRow = .MouseRow
    
                        
                        'highlight rows that can be dropped on
                        For i = 1 To .Rows - 1
                            If .TextMatrix(i, 0) = "Not known" Then
                                Call HighlightCell(i, True)
                            End If
                        Next
                        
                    End If
    Here (for the sake of completeness) is the drag-drop code:

    Code:
    Private Sub MSFlexGrid1_DragDrop(Source As Control, X As Single, y As Single)
    
        Dim i As Integer, ConfirmUpdate As Boolean
        
        If Source Is Me.MSFlexGrid1 Then
        
            With Me.MSFlexGrid1
            
                If .MouseRow > 0 Then
            
                    If .MouseCol = 0 Then
                        .Row = .MouseRow
                        .Col = .MouseCol
                        If .TextMatrix(.MouseRow, 0) <> "Not known" Then
                            MsgBox ("This number is already known. To edit it, double click the number.")
                            'reset the cells to white
                            For i = 1 To .Rows - 1
                                Call HighlightCell(i, False)
                            Next
                        Else
                            'reset all rows to white
                            For i = 1 To .Rows - 1
                                Call HighlightRow(i, False)
                            Next
                            'highlight the drag cell again
                            .Row = DragRow
                            .Col = 0
                            .CellBackColor = &HFFFF80
                            
                            'highlight the whole drop row
                            Call HighlightDropRow(.MouseRow, True)
                            DropRow = .MouseRow
                            
                            'get confirmation
                            ShowMsg = MsgBox("To associate " & strDragText & " with the highlighted product, click Okay.", vbOKCancel + vbExclamation, "Associate")
                            
                            If ShowMsg = 1 Then
                            
                                Set DBCall = New DBCallDlg
                                    'MsgBox ("Drag Row = " & DragRow & ", Drop Row = " & DropRow)
                                    'MsgBox (strDragText & ", " & .TextMatrix(DropRow, 6) & ", " & .TextMatrix(DragRow, 6) & ", " & .TextMatrix(DragRow, 8))
                                    ConfirmUpdate = DBCall.UpdateProductWithNumber(strDragText, .TextMatrix(DropRow, 6), .TextMatrix(DragRow, 6), .TextMatrix(DragRow, 8))
                                Set DBCall = Nothing
                                
                                're-set the list
                                Call GetProducts(UserID)
                                
                            ElseIf ShowMsg = 2 Then
                        
                            Else
                                MsgBox ("An error occurred. The number was not updated. Please try again.")
                                'reset all rows to white
                                For i = 1 To .Rows - 1
                                    Call HighlightRow(i, False)
                                Next
                            End If
                                
                            '.TextMatrix(.MouseRow, .MouseCol) = strDragText
                        End If
                        
                    End If
                    
                End If
                
            End With
            
        End If
        
    End Sub
    So, currently, you click on a cell and the cell highlights and any cell in the same column that is available to be dropped on also changes (to a different) colour.

    My question is:

    What I want to happen is that, as you drag over cells that are available to be dropped on, they change to (another) different colour - so it is easy to see which cell you are about to drop on. How can I do this?

    Thanks for any help.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Highlighting cells when dragging over

    A shameless bump to see if any of you guys in the States can help me with this.

    Basically, let's say I am dragging the contents of row 8, cell 0 and am going to drop it on row 2, cell 0

    On the way row 6, cell 0, is 'suitable' to be dropped on and so is row 5, cell 0

    As I am dragging, as I mouseover the two cells that are suitable to be dropped on, how can I tell I am over them to get them to change colour to say 'Hey, look, you can drop on me!'

    Cheers

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Highlighting cells when dragging over

    Hi, as there are no replies to this ... can I ask the mods if I have phrased the question in such a way as people aren't clear what I need ... or can't it be done?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width