Reputation:
I have a list view with fixed and dynamic items. I intend to print it as a receipt for payment validation
This is how I am adding the fixed items
Dim ListItem As ListViewItem
ListItem = ListView1.Items.Add("ST PAUL'S SECONDARY SCHOOL")
Dim logo As ListViewItem
logo = ListView1.Items.Add(Image.FromFile("1.png"))
My problem is that the line for adding the image is giving me the following error
Error BC30518 Overload resolution failed because no accessible 'Add' can be called with these arguments: 'Public Overridable Overloads Function Add(text As String) As ListViewItem': Value of type 'Image' cannot be converted to 'String'. 'Public Overridable Overloads Function Add(value As ListViewItem) As ListViewItem': Value of type 'Image' cannot be converted to 'ListViewItem'. SchoolManager C:\Users\MASENO\Source\Repos\SchoolManager\SchoolManager\Pay Fees.vb 18 Active
I have tried this code to add the image from resources but it is not adding any image and displaying no error
Dim il = New ImageList()
il.Images.Add("1", My.Resources.barlogo)
ListView1.LargeImageList = il
ListItem.ImageKey = "1"
What could I be doing wrong and how can I rectify it?
Upvotes: 0
Views: 3959
Reputation: 15774
Use an ImageList to hold your image, then apply it to the ListView by key.
' your code
Dim ListItem As ListViewItem
ListItem = ListView1.Items.Add("ST PAUL'S SECONDARY SCHOOL")
' new code
Dim il = new ImageList()
il.Images.Add("1", Image.FromFile("1.png"))
ListView1.LargeImageList = il
ListItem.ImageKey = "1"
Upvotes: 1