我试图为影片标题的第一个字母在listview对象中设置一个列表。
我在互联网上找到了一个工作代码,从中得到启发,我改变了我的代码。 在调试中,我看到由初始字母表示的已正确分配的组(我将所有不以字母开头的字符都以“#”分组)。 在包含listview对象的表单中,列表未分组,我也不明白为什么。
非常感谢您提供任何建议。
这是我写的代码
lvFilmDetail.BeginUpdate()
lvFilmDetail.Items.Clear()
Dim ws_firstLetter_svd As Char = ""
Dim ctr_group As Integer = -1
For Each ws_film In ws_elenco_film
Dim item As New ListViewItem(ws_film.Get_Titolo)
CreateGroup(ws_film.Get_Titolo, ws_firstLetter_svd, item)
lvFilmDetail.Items.Add(item)
Next
lvFilmDetail.Columns.Item(4).Width = 0
lvFilmDetail.EndUpdate()
End If
End Sub
Private Sub CreateGroup(ByVal ws_title As String, ByRef ws_firstLetter_svd As Char, ByRef item As ListViewItem)
Dim ws_firstLetter As Char
ws_firstLetter = ws_title
Dim lvFilmDetailGroup As ListViewGroup
Select Case Asc(ws_firstLetter)
Case < 65
ws_firstLetter = "#"
Case > 122
ws_firstLetter = "#"
Case 91 To 96
ws_firstLetter = "#"
End Select
If ws_firstLetter <> ws_firstLetter_svd Then
lvFilmDetailGroup = New ListViewGroup(ws_firstLetter)
lvFilmDetail.Groups.Add(lvFilmDetailGroup)
End If
item.Group = lvFilmDetailGroup
End Sub
我在项目和示例中比较了列表视图的属性,但没有发现任何区别,除了网格和示例中不存在的上下文菜单的存在
这些是我的程序和示例的屏幕截图:
分组错误:
分组示例:
这是我的代码,做了一些更改后,我仍然遇到相同的问题:
Dim lvFilmDetailGroup As ListViewGroup
Dim ws_firstLetter As Char = ""
Dim ws_firstLetter_svd As Char
Dim ctr_group As Integer = -1
For Each ws_film In ws_elenco_film
ws_firstLetter = ws_film.Get_Titolo
Select Case Asc(ws_firstLetter)
Case < 65
ws_firstLetter = "#"
Case > 122
ws_firstLetter = "#"
Case 91 To 96
ws_firstLetter = "#"
End Select
If ws_firstLetter <> ws_firstLetter_svd Then
'$$$ accorpare caratteri diversi dalle lettere
ctr_group += 1
lvFilmDetailGroup = New ListViewGroup(ctr_group.ToString, ws_firstLetter)
lvFilmDetail.Groups.Add(lvFilmDetailGroup)
ws_firstLetter_svd = ws_firstLetter
End If
Dim item As New ListViewItem(ws_film.Get_Titolo)
item.Group = lvFilmDetailGroup
lvFilmDetail.Items.Add(item)
Next
lvFilmDetail.Columns.Item(4).Width = 0
lvFilmDetail.EndUpdate()
End If
答案 0 :(得分:0)
我解决了!!我已在主程序中将此语句添加到运行表单之前:Application.EnableVisualStyles()。 有了这段代码,我看到了分组。