'VB.net的,你看一下,VB6的也有,先这个吧 Public Function GetListView(ByRef lvListView As ListView, ByVal SQLString As String) As Boolean
Using da As New SqlDataAdapter(SQLString, cnn) Dim dt As New DataTable Try da.Fill(dt) Catch ex As Exception Return False End Try
Dim c As Integer Dim cs As Integer()
ReDim cs(0) With lvListView .Items.Clear() '建立结构
Dim lch As ColumnHeader 'Dim lg As ListViewGroup
'.Columns.Clear()
For c = 0 To dt.Columns.Count - 1 lch = .Columns.Add(dt.Columns(c).Caption) ReDim Preserve cs(c)
Next
If .Columns.Count < dt.Columns.Count Then
For c = 0 To .Columns.Count - 1
.Columns(c).Text = dt.Columns(c).Caption ReDim Preserve cs(c) Next
For c = .Columns.Count To dt.Columns.Count - 1 lch = .Columns.Add(dt.Columns(c).Caption) ReDim Preserve cs(c) Next Else For c = 0 To dt.Columns.Count - 1 .Columns(c).Text = dt.Columns(c).Caption ReDim Preserve cs(c) Next
Do Until .Columns.Count = dt.Columns.Count .Columns.RemoveAt(.Columns.Count - 1) Loop
End If
Dim Row As DataRow Dim d As Double Dim s As String
For c = 1 To dt.Columns.Count - 1 s = Row(c).ToString If IsNumeric(s) Then Try d = Convert.ToDouble(s) Item.SubItems.Add(d) Catch ex As Exception Item.SubItems.Add(s) End Try Else Item.SubItems.Add(s) End If
Next .Items.Add(Item)
Next
End With
dt.Dispose() da.Dispose()
End Using End Function
长双眼皮的鱼
2024-10-02 16:53:45
上面的这些和其他的类似 ...... While dr.Read listbox.Items.Add(dr(0).ToString) End While ......