ListBox WIDTHACTUAL not working??????

  1. 3 months ago

    Dave S

    Mar 9 San Diego, California USA

    I am trying to detect when the mousecursor is near the right edge of either column 0 or column 1 in a Listbox
    on only the first 3 rows

    Sub MouseMove(X As Integer, Y As Integer) Handles MouseMove
      Const tolerance=8
      Dim w As Integer
      Dim i As Integer
      coldrag=(-1)
      w=0
      If y<=Me.RowHeight*3 Then 
        For i=0 To 1
          w=w+Me.Column(i).WidthActual   // <-------------- THIS IS ALWAYS ZERO, when in fact the listbox (ME) has 8 columns all > 100px wide
    // It does in fact get here
          If x>=(w-tolerance) And x<=(w+tolerance) Then 
            colDrag=i
            Exit For
          End If
        Next i
      End If
      If colDRAG>=0 Then 
        Me.MouseCursor=System.Cursors.SplitterEastWest
      Else
        Me.MouseCursor=System.Cursors.StandardPointer
      End If
      
    End Sub
  2. Dave S

    Mar 9 San Diego, California USA
    Edited 3 months ago

    Strange.... if I go from 0 to 3 if "works".... but it says column 0 and column 1 are ZERO width, but column 2 and column 3 are 120

    Colwidths is "*,*,120,120,120,120,*".... but isn't WidthActual supposed to return what the column IS and in "ACTUAL"????

  3. Andre K

    Mar 10 Pre-Release Testers

    Dave, i tried your code with a few small changes and i get the right values (on Windows 10). I have a label below the listbox that gives the accumulated values of the columnwidths and it shows the exact values even if i resize columns. Here is the code i tried:

    Const tolerance = 8
    Dim w As Integer
    Dim i As Integer
    Dim coldrag As Integer
    coldrag = (-1)
    w = 0
    If y <= Me.RowHeight * 3 Then 
    For i = 0 To Me.ColumnCount - 1
    w = w + Me.Column(i).WidthActual   // <-------------- THIS IS ALWAYS ZERO, when in fact the listbox (ME) has 8 columns all > 100px wide
    
    Label1.Text = str(w)
    
    // It does in fact get here
    If x >= (w - tolerance) And x <= (w + tolerance) Then 
    colDrag = i
    Exit For
    End If
    Next i
    End If
    If colDRAG >= 0 Then 
    Me.MouseCursor = System.Cursors.SplitterEastWest
    Else
    Me.MouseCursor = System.Cursors.StandardPointer
    End If

or Sign Up to reply!