Hi everyone,
I'd appreciate if anyone could give a hand on the next problem:
Ive got a userform that has 4 textboxs, a combobox, two command buttons and a MULTICOLUMN listbox.
The listbox is populated from the textboxes/combobox after the commandbutton1 is clicked. My problem is Im trying to add headers to the listbox, however ive seen in previous threads that since the listbox is populated from textbox and not from a worksheet this cant be done, is this true? If so, how can I add a first row that works as header.
The listbox has 5 columns and I need the headers to say:
P/N---Description----Qty---M.U.---Batch
HOWEVER, i have a second commandbutton that allows the user to DELETE a row selected from the listbox, so I need to lock the possibility of the user to delete the first row but delete any other row he selects. I cant use labels cause Ive written the code so that the columns autosize and so if I put a Label o top of the Listbox its never well positioned.
heres my code if it helps.
Private Sub CommandButton1_Click()
ListBox1.AddItem TextBox1.Value
ListBox1.List(ListBox1.ListCount - 1, 1) = TextBox2.Value
ListBox1.List(ListBox1.ListCount - 1, 2) = TextBox4.Value
ListBox1.List(ListBox1.ListCount - 1, 3) = TextBox3.Value
ListBox1.List(ListBox1.ListCount - 1, 4) = ComboBox1.Value
' From here on its the autosize code
With ListBox1
.ColumnCount = 5
For i = 1 To .ColumnCount
With Me.Controls.Add("Forms.TextBox.1", Name:="txtTemp" & i)
.AutoSize = True
.MultiLine = True
.WordWrap = False
.SelectionMargin = False
With .Font
.Name = ListBox1.Font.Name
.Size = ListBox1.Font.Size
End With
End With
Next i
For i = 0 To .ListCount - 1
Me.Controls("txtTemp1").Text = Me.Controls("txtTemp1").Text & vbCr & .List(i, 0)
Me.Controls("txtTemp2").Text = Me.Controls("txtTemp2").Text & vbCr & .List(i, 1)
Me.Controls("txtTemp3").Text = Me.Controls("txtTemp3").Text & vbCr & .List(i, 2)
Me.Controls("txtTemp4").Text = Me.Controls("txtTemp4").Text & vbCr & .List(i, 3)
Me.Controls("txtTemp5").Text = Me.Controls("txtTemp5").Text & vbCr & .List(i, 4)
Next i
For i = 1 To .ColumnCount
StrCwidths = StrCwidths & Me.Controls("txtTemp" & i).Width & ";"
lngTotalWidth = lngTotalWidth + Me.Controls("txtTemp" & i).Width
Me.Controls("txtTemp" & i).Visible = False
Me.Controls.Remove ("txtTemp" & i)
Next i
.Width = lngTotalWidth + ListBox1.ColumnCount + 6
.ColumnWidths = StrCwidths
End With
End Sub
Thanks a lot in advance for the answers.
Bookmarks