gpt4 book ai didi

.net - Listview 列标题不显示 VB.Net

转载 作者:行者123 更新时间:2023-12-04 22:34:58 24 4
gpt4 key购买 nike

我没有在 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 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

关于.net - Listview 列标题不显示 VB.Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9107942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com