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.
Here (for the sake of completeness) is the drag-drop code: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
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.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
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.




Reply With Quote