Listbox Column Resize

Can a listbox have a column width change by dragging if it has a HEADER row?
I have a listbox where a header is not appropriate, and I can’t seem to get a drag type column resize to even activate :frowning:

there are 8 columns… columns 0 and 1 should be adjustable by the user
2 thru 6 are fixed at 120px wide
and column 7 is flexible as the window is resized (column 0 and 1 should only change per the user, not window resize)

here is the OPEN code for the listbox

its gonna to be a simple Gannt chart

Sub Open() Handles Open
  // First THREE(3) Rows are "Headers"
  Dim i As Integer
  Dim s As String
  Me.ColumnCount         = 8
  Me.ColumnsResizable    = True
  Me.ScrollBarHorizontal = True
  Me.ScrollBarVertical   = True
  Me.DeleteAllRows
  Me.ColumnWidths="*,*,120,120,120,120,120,*"
  //
  // Year
  //
  Me.addRow  
  s=""
  For i=0 To 7
    //Me.column(i).UserResizable=(i<2) // only column 0 and 1 are resizeable
    Me.CellBorderTop(0,i)=Listbox.BorderThinSolid
    Me.CellBorderBottom(0,i)=Listbox.BorderThinSolid
    Me.CellBorderRight(0,i)=Listbox.Bordernone
    Me.CellBorderleft(0,i)=Listbox.Bordernone
    Select Case i
    Case 7
      Me.CellBorderLeft(0,i)=Listbox.BorderThinSolid
      Me.CellBorderRight(0,i)=Listbox.BorderThinSolid
      s="[YEAR]"
    End Select
    Me.cell(0,i)=s
  Next i
  //
  // Month
  //
  Me.addRow  
  
  For i=0 To 7
    Me.CellBorderBottom(1,i)=Listbox.Bordernone
    Me.CellBorderRight(1,i)=Listbox.BorderThinSolid
    Me.CellBorderleft(1,i)=Listbox.BorderThinSolid
    Select Case i
    Case 0
      s="Task"
    Case 1
      s="Assigned"
    Case 2,3
      s="Estimated"
    Case 4,5
      s="Actual"
    Case 6
      s="Percent"
    Case 7
      s="[MONTH]"
    End Select
    Me.cell(1,i)=s
  Next i
  // Days
  Me.addRow
  For i=0 To 7
    Me.CellBorderBottom(2,i)=Listbox.BorderThinSolid
    Me.CellBorderRight(2,i)=Listbox.BorderThinSolid
    Me.CellBorderleft(2,i)=Listbox.BorderThinSolid
    Select Case i
    Case 0
      s="Description"
    Case 1
      s="To"
    Case 2,4
      s="Start"
    Case 3,5,6
      s="Complete"
    Case 7
      s="[DAYS]"
    End Select
    Me.cell(2,i)=s
  Next i
  
  Me.addRow
  For i=0 To 7
    Select Case i
    Case 0
      s="This is just a test"
    Case 1
      s="Baker Electric"
    Case 2 To 6
      s="WWW 88,8888"
    Case 7
      s="[XXX]"
    End Select
    Me.cell(3,i)=s
  Next i
  
End Sub

I don’t put “*” in a resizeable column, but nothing. does this help ?

Drag columnresizing is only possible through the headers.

yeah… I ultimately determined that… so I was forced to write my own column resize routine… fortunately it works quite well.

I knew without any doubt that you were capable to do that, gratulations!

Dave, would you be willing to share it? I’ve been trying to do a similar routine but haven’t succeeded yet. I’d like to see how you did it and take it from there. (We all know you’re a better programmer than I am.)

Certainly… bear in mind that you will need to adjust based on your specific situation… this is just rough cut/paste from my project

these are all events of a Listbox subclass
and the listbox MUST have values in COLUMNWIDTHS for any column to be resized … ‘’ won’t work. in my app I am only allowing the first two to be resized, and the last column is '

Private Property colDRAG as Integer
Private Property zMouseX as Integer
Private Property zMouseY as Integer
Private Property zColumnWidths as string
Function MouseDown(x As Integer, y As Integer) Handles MouseDown as Boolean
  zMouseX=x
  zMouseY=y
  Return (IsContextualClick=False)
End Function
Sub MouseMove(X As Integer, Y As Integer) Handles MouseMove
// changes cursor as it nears edge of a column
  Const tolerance=8
  Dim w As Integer
  Dim i As Integer
  coldrag=(-1)
  w=0
  If y<=Me.RowHeight*2 Then 
    For i=0 To 1 // I only allow first two columns to be resized
      w=w+Me.Column(i).WidthActual
      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
    mouseW=Me.column(colDRAG).WidthActual
  Else
    Me.MouseCursor=System.Cursors.StandardPointer
  End If
 
End Sub
Sub MouseDrag(x As Integer, y As Integer) Handles MouseDrag
  Dim w As Integer
  If coldrag>=0 Then 
    w=mouseW+(x-zMouseX)
    If w<zDefaultColumnWidth Then Return
    setColumnWidth(colDRAG,w)
  End If
End Sub
Sub MouseUp(x As Integer, y As Integer) Handles MouseUp
  colDrag=(-1)
End Sub
Private Sub setColumnWidth(col as integer, wide as integer)
  Dim v() As String
  If col=8 Then Return // this column must always be '*'
  v=Split(zColumnWidths,",")
  v(col)=Str(wide)
  zColumnWidths=Join(v,",")
  listbox1.columnwidths=zColumnwidths
End Sub

I store the columnWidths as zCOLUMNWIDTHS as the same values need to be applied to 2 different listboxes

Thanks, Dave.