B4J Question Reading Mouse position on CLV when moving with button pressed


Active Member
Licensed User
Longtime User
I have an app where I need to know what row in the clv the mouse is over as I move it with the right button held down.
I have no problem when no buttons are pressed, using the _MouseEntered event. But when I hold the right button down and move the mouse, the _MouseEntered event no longer triggers - except when moving back and forth over the specific row where the mouse button was pressed down.
Moving the mouse over the clv in the attached project logs the results - move the mouse over the clv, then do the same with either button held down.

Is there a way to do what I am looking for?


  • MouseEntered.zip
    4.2 KB · Views: 116


Active Member
Licensed User
Longtime User
The problem is that it is treated as a drag action. Two untested options:
1. Use jDragAndDrop and cancel the drag option: https://www.b4x.com/android/forum/threads/jdraganddrop2-drag-and-drop.76168/#content
My guess is that it will not work.

I used the "built-in drag code (without the jDragAndDrop library) as follows

' MousePressed is triggered when the mouse button is pressed
Sub pnlItem_MousePressed (Eventdata As MouseEvent)
    ' Log($"Sub: pnlTabFixed_MousePressed in ${mName}"$)
    Dim pnl As B4XView = Sender
    Dim mClickedItem As Int
    mClickedItem = CLV.GetItemFromView(pnl)
    ' To prevent doubleclicking
    If Eventdata.SecondaryButtonPressed Then
        Dim OldDestination As Int = mClickedItem
        Dim pnlx As B4XView = CLV.GetPanel(mClickedItem).Parent
        ' Starting offset is the top of the clicked panel
        Dim AbsOffset As Int = pnlx.Top
        Dim offset As Int
        Do While True
            Wait For (pnl) pnlItem_MouseDragged (edata As MouseEvent)
            '' The code below freezes, and freezes the display, after the first time it scrolls the clv
            If offset < CLV.sv.ScrollViewOffsetY + 3*pnlx.Height Then
                CLV.sv.ScrollViewOffsetY = Max(0, CLV.sv.ScrollViewOffsetY - 10dip)
            Else If CLV.sv.ScrollViewOffsetY + CLV.sv.Height < offset + 3*pnlx.Height Then
                CLV.sv.ScrollViewOffsetY = CLV.sv.ScrollViewOffsetY + 10dip
            End If
            '' The code above freezes, and freezes the display, after the first time it scrolls the clv
            offset = AbsOffset + edata.y
            Dim Destinationindex As Int = CLV.FindIndexFromOffset(offset)
            If Destinationindex <> OldDestination Then
                OldDestination = Destinationindex
            End If
    End If
End Sub

Sub Display_Row (Index As Int)
    lblRowDisplay.Text = $"Mouse is over Row containing Item #${Index+1}"$
End Sub

Without the scrolling section it works, but I don't understand why the scrolling section only works briefly and then stops the rest from working (project attached).


  • MouseEntered1.zip
    4.6 KB · Views: 137
Upvote 0