Listview and Custom Class

  • Thread starter Thread starter D Miller
  • Start date Start date
D

D Miller

Hello,

I want to use a class I have created, when I do I receive an error message
that says the class can not be converted to string and another message
saying that the class can not be converted to
windows.systems.forms.listviewitem.

I created a function called ToString in my class and that did not seem to
make a difference..

Anyone have any suggestions?

Thank you,
David
 
* "D Miller said:
I want to use a class I have created, when I do I receive an error message
that says the class can not be converted to string and another message
saying that the class can not be converted to
windows.systems.forms.listviewitem.

I created a function called ToString in my class and that did not seem to
make a difference..

"Post code!"
 
The code from the app.... (There is a Listview called "LV" on the form....)


Dim Info1 As New Info()

With Info1

.. LineNumber = LV.Items.Count + 1

End With

Dim ListItem As ListViewItem

ListItem = LV.Items.Add(Info1)




The code for the class call "info"

Dim mIsGun As Boolean

Dim mOnHandId As Integer

Dim mLineNumber As Integer

Dim mTransaction As Integer

Sub New(Optional ByVal LineNumber As Integer = 0)

mLineNumber = LineNumber

mOnHandId = -1

End Sub

Public Property IsGun() As Boolean

Get

Return mIsGun

End Get

Set(ByVal Value As Boolean)

mIsGun = Value

End Set

End Property

Public Property OnHandId() As Integer

Get

Return mOnHandId

End Get

Set(ByVal Value As Integer)

mOnHandId = Value

End Set

End Property

Public Property LineNumber() As Integer

Get

Return mLineNumber

End Get

Set(ByVal Value As Integer)

mLineNumber = Value

End Set

End Property

Public Property Transaction() As Integer

Get

Return mTransaction

End Get

Set(ByVal Value As Integer)

mTransaction = Value

End Set

End Property

Public Overrides Function ToString() As String

Return mLineNumber.ToString("000")

End Function



End Class
 
* "D Miller said:
The code from the app.... (There is a Listview called "LV" on the form....)

Dim Info1 As New Info()

With Info1

. LineNumber = LV.Items.Count + 1

End With

Dim ListItem As ListViewItem

ListItem = LV.Items.Add(Info1)

Create a standard ListView item and assign the 'Info' to its 'Tag'
property. Then add the standard item to the control.
 
* "D Miller said:
What's the code to accomplish this?

\\\
Dim mi As New MyInfo
mi.Foo = 1
mi.Baz = "Goo"
Dim lvi As ListViewItem = ...
lvi.Tag = mi
///

\\\
MsgBox(DirectCast(Me.ListView1.Items(10).Tag, MyInfo).Goo)
///
 
Back
Top