Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET ListView
I am having the hardest time with ListView today. The code looks good but when i run it i do not see data in the ListView (it's just totally blank). Please help, I have tried everything but still can't get it to working
 

Dim T As New Form1
 
Dim arr(3) As String
 
arr(0) = "a"
arr(1) = "b"
arr(2) = "c"
arr(3) = "d"
 
Dim itm As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(arr)
 
T.ListViewRev.Items.Add(itm)
 
T.ShowDialog()
Posted 18-Feb-13 16:41pm
juno101334
Comments
Sergey Alexandrovich Kryukov at 18-Feb-13 23:17pm
   
Please add the tag: WinForms.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
i suggest you to bind the list view on Load event of Form1.
 
'Open the Form1
Dim T As New Form1
T.ShowDialog()
'Form1 Load event
Protected Sub Form1_Load(sender As Object, e As EventArgs)
 
'Bind the list view
Dim arr(3) As String
 
arr(0) = "a"
arr(1) = "b"
arr(2) = "c"
arr(3) = "d"
 
Dim itm As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(arr)
 
ListViewRev.Items.Add(itm)
End Sub
 
hope it works.
  Permalink  
Comments
juno101 at 19-Feb-13 11:42am
   
I guess the only way to populate the ListView is to have the code run inside the Form Sub (Form1_Load). Interesting, considering that one can populate a ListBox via creating a Form object and dumping data into the TextBox, ListBox . . . .
 
I still don't understand . . . I am able to just move my code to the Form Sub. However it would be nice to understand why one can not populate data via creating an instance of the Form class and pushing data into it's ListView .
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is not how it works. This constructor of ListViewItem creates an item with sub-items:
http://msdn.microsoft.com/en-us/library/faw83h4f.aspx[^].
 
Sub-items are used in the View with the value System.Windows.Forms.View.Details, which show Columns, so you need to set the View property, define columns, etc. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.view.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx[^].
 
The last MSDN page referenced above shows a code sample with Details, Columns and sub-items. If this is what you wanted, check it and add what is missing from your code. If you need different kind of view, read the documentation more.
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I think the problem was that i needed to add a column
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 245
1 OriginalGriff 210
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,157
2 Maciej Los 3,774
3 Peter Leow 3,448
4 CHill60 2,702


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100