Listview列标题未显示VB.Net
我没有在listView中获取列标题。只有一项(0)未显示子项。这是我的密码。告诉我有什么问题。 先谢谢你Listview列标题未显示VB.Net,.net,vb.net,winforms,listview,.net,Vb.net,Winforms,Listview,我没有在listView中获取列标题。只有一项(0)未显示子项。这是我的密码。告诉我有什么问题。 先谢谢你 Dim PTCode As Integer = CInt(ChildPatnameTag) ClearSQl() CheckState() strSql = "select tCode,tprice from patTests where pCode=" & PTCode strConn.Open() Dim TCmdSelect As New O
Dim PTCode As Integer = CInt(ChildPatnameTag)
ClearSQl()
CheckState()
strSql = "select tCode,tprice from patTests where pCode=" & PTCode
strConn.Open()
Dim TCmdSelect As New OleDbCommand(strSql, strConn)
Dim TReader As OleDbDataReader = TCmdSelect.ExecuteReader()
'Column Header
Dim header1, header2 As ColumnHeader
header1 = New ColumnHeader
header1.TextAlign = HorizontalAlignment.Left
header1.Text = "Test"
header1.Width = 250
header2 = New ColumnHeader
header2.TextAlign = HorizontalAlignment.Left
header2.Text = "Price"
header2.Width = 50
With lvwPatTests
.CheckBoxes = True
.GridLines = True
.FullRowSelect = True
.HideSelection = False
.MultiSelect = False
.Columns.Add("Test")
.Columns.Add("Price")
End With
If TReader.HasRows Then
Do While TReader.Read
ClearSQl()
strSql = "Select tName from tests where tCode=" & TReader("tCode")
Dim TCCmdSelect As New OleDbCommand(strSql, strConn)
Dim TCReader As OleDbDataReader = TCCmdSelect.ExecuteReader()
If TCReader.HasRows Then
Do While TCReader.Read
For i = 0 To TCReader.FieldCount - 1
' Create List View Item (Row)
Dim lvi As New ListViewItem
' First Column can be the listview item's Text
lvi.Text = TCReader.Item("tName").ToString
' Second Column is the first sub item
lvi.SubItems.Add(TReader.Item("tprice"))
MsgBox(TCReader.Item("tName").ToString)
MsgBox(TReader.Item("tprice"))
' Add the ListViewItem to the ListView
lvwPatTests.Items.Add(lvi)
Next
Loop
TCCmdSelect.Dispose()
TCReader.Close()
TCReader = Nothing
Else
TCCmdSelect.Dispose()
TCReader.Close()
TCReader = Nothing
End If
Loop
TReader.Close()
TReader = Nothing
End If
您需要将ListView控件的View属性更改为
Details
,以便查看列和子项:
With lvwPatTests
.View = View.Details
.CheckBoxes = True
.GridLines = True
.FullRowSelect = True
.HideSelection = False
.MultiSelect = False
.Columns.Add("Test")
.Columns.Add("Price")
End With
您已经拥有了这些对象。请把它们传进来:
With lvwPatTests
.CheckBoxes = True
.GridLines = True
.FullRowSelect = True
.HideSelection = False
.MultiSelect = False
.Columns.Add(header1)
.Columns.Add(header2)
End With
将对象设置为
Nothing
是没有意义的。虽然您确实需要对实现IDisposable
的对象调用Dispose
方法,但最好使用语句将它们的创建封装在中。这段代码中有很多“噪音”。可能是重复的