listbox.Columnwidths question

  • Thread starter Thread starter Stuart
  • Start date Start date
S

Stuart

The following statement does not appear to have
effect:

Private Sub frmName_Contractors_Initialize()
lbDataCode.Width = 100
lbDataCode.ColumnCount = 2
lbDataCode.ColumnWidths = "6;94"
End Sub

I've changed the overall width.....increasing it
I've narrowed column1 and widened 2.
Columnwidths are not set in the listbox object.

Why are the changes not being seen in the form,
please?

Regards.
 
open a new workbook.

Add a userform.

Useform1
textbox1 textbox2 textbox3

listbox1

put three textboxes above the listbox. Make the userform significantly
wider than the listbox

Put in the following code

Private Sub TextBox1_Change()
ListBox1.Width = CLng(TextBox1.Value)
End Sub

Private Sub TextBox2_Change()
ListBox1.ColumnWidths = Trim(TextBox2.Value) & ";" & Trim(TextBox3.Value)
End Sub

Private Sub TextBox3_Change()
ListBox1.ColumnWidths = Trim(TextBox2.Value) & ";" & Trim(TextBox3.Value)
End Sub

Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 2
For i = 1 To 10
With ListBox1
.AddItem "AAAAAAAAAAAAAAAAAAAAAAAAA"
.List(.ListCount - 1, 1) = "BBBBBBBBBBBBBBBBBBBBBBBBB"
End With
Next
End Sub

Put in a width for the listbox in textbox1. Then put in a width for column
1 in textbox2 and a width for column 2 in textbox3.

play with the settings by changing the values in the textboxes.

Anyway, worked fine for me.
 
Back
Top