Hur gör man för att bestämma bredden på kolumnerna . Vet inte vad du är ute efter. Men du kanske kan använda något av detta?Listbox problem
Så här ser min kod ut just nu, men jag förstår inte riktigt hur jag ska skriva in hur breda mina 3 kolumner ska vara.
Public Sub FillListView(lvw As ListView, lvrs As ADODB.Recordset, status As Integer)
' har vi verkligen fått in ett recordset?
If Not IsObject(lvrs) Then
status = -1
Exit Sub
End If
If Not (lvrs.EOF Or lvrs.BOF) Then
maxcols = lvrs.Fields.Count - 1
For a = 0 To maxcols
lvw.ColumnHeaders.Add , , lvrs(a).Name, ListView1.Width / 3
Next
Do While Not lvrs.EOF
B = B + 1
Key = Chr(B + 64)
lvw.ListItems.Add B, Key & CStr(a), lvrs(0)
For a = 1 To maxcols
If Not IsNull(lvrs(a)) Then
lvw.ListItems.Item(B).ListSubItems.Add , , lvrs(a)
Else
lvw.ListItems.Item(B).ListSubItems.Add , , "<null>"
End If
If lvrs(a).Name = "Freight" Then ' 7
lblTotalFreigth = lblTotalFreigth + lvrs(a)
End If
Next
lvrs.MoveNext
Loop
End If
End Sub
AndersSv: Listbox problem
<code>
Public Function FillListView(ListView As MSComctlLib.ListView, Recordset As ADODB.Recordset) As Long
Dim fldField As ADODB.Field
Dim ColumnWidth As Long
Dim Item As MSComctlLib.ListItem
Dim Items As MSComctlLib.ListItems
If ListView Is Nothing Then
Err.Raise 5, "FillListView", "Invalid procedure call: ListView not set"
ElseIf Recordset Is Nothing Then
Err.Raise 5, "FillListView", "Invalid procedure call: Recordset not set"
Else
Set Items = ListView.ListItems
ListView.ColumnHeaders.Clear
If Recordset.EOF Or Recordset.BOF Then
Else
ColumnWidth = ListView.Width / Recordset.Fields.Count
For Each fldField In Recordset.Fields
ListView.ColumnHeaders.Add , , fldField.Name, ColumnWidth
Next
Do Until Recordset.EOF
Set Item = Items.Add(, , Recordset(0))
For a = 1 To maxcols
Set fldField = Recordset(a)
If IsNull(fldField.Value) Then
Item.ListSubItems.Add , , "<Null>"
Else
Item.ListSubItems.Add , , fldField.Value
End If
Next
lblTotalFreigth = lblTotalFreigth + Recordset("Freight")
Recordset.MoveNext
Loop
End If
End If
End Function
</code>