我试图在我的应用程序中实现listview对象,但是由于某种原因,我的listview没有在任何项目上显示文本。项目已添加,并显示小图标。
我想要的结果(截屏www)。
我当前的结果
下面是我用来生成列表视图的代码。使用设计器将列表视图添加到winform中。
Public Class OccurrenceControl
' Local variable
Private _occurrence As Inventor.ComponentOccurrence
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Create a new image list
Dim imageList As ImageList = New ImageList()
imageList.ImageSize = New Drawing.Size(32, 32)
imageList.Images.Add(My.Resources.MateConstraint)
imageList.Images.Add(My.Resources.AngleConstraint)
imageList.Images.Add(My.Resources.TangentConstraint)
imageList.Images.Add(My.Resources.InsertConstraint)
' Set the listview small images list
lvConstraints.SmallImageList = imageList
' Make the list scrollable
lvConstraints.Scrollable = True
' Set the listview view type
lvConstraints.View = View.List
End Sub
Public Sub ShowInfo(ByVal Occurrence As Inventor.ComponentOccurrence)
' Populate the local variable with the passed occurrence
_occurrence = Occurrence
' Clear all listed constraints
lvConstraints.Items.Clear()
' Set the grounded checkbox value
cbGrounded.Checked = Occurrence.Grounded
' Loop all constraints.
For Each oConstraint As Inventor.AssemblyConstraint In Occurrence.Constraints
' Create a new listview item
Dim oListItem As New ListViewItem
' Give the listview item a name
oListItem.Name = oConstraint.Name
' Add a image based on the constraint type.
If oConstraint.Type = Inventor.ObjectTypeEnum.kFlushConstraintObject Or Inventor.ObjectTypeEnum.kMateConstraintObject Then
oListItem.ImageIndex = 0
ElseIf oConstraint.Type = Inventor.ObjectTypeEnum.kAngleConstraintObject Then
oListItem.ImageIndex = 1
ElseIf oConstraint.Type = Inventor.ObjectTypeEnum.kTangentConstraintObject Then
oListItem.ImageIndex = 2
ElseIf oConstraint.Type = Inventor.ObjectTypeEnum.kInsertConstraintObject Then
oListItem.ImageIndex = 3
End If
' Add the new listview item to the listview
lvConstraints.Items.Add(oListItem)
Next
End Sub
End Class
答案 0 :(得分:1)
您不会在任何地方设置Text
中的ListViewItem
,因此不会显示任何文本也就不足为奇了。