Problems instering items into a listview

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 31
Reputation: AaronASterling is an unknown quantity at this point 
Solved Threads: 5
AaronASterling's Avatar
AaronASterling AaronASterling is offline Offline
Light Poster

Problems instering items into a listview

 
0
  #1
Dec 24th, 2007
Hello All,


I have a user define class,


  1. <Serializable()> Public Class City
  2.  
  3. Public Name As String = ""
  4. Public State As String = ""
  5. Public URL As String = ""
  6.  
  7. Public Sub New(ByVal state As String, ByVal name As String, ByVal url As String)
  8.  
  9. me.State = state
  10. me.Name = name
  11. me.URL = url
  12.  
  13. End Sub
  14.  
  15. Public Function isValid() As Boolean
  16.  
  17. If me.Name <> "" And _
  18. me.State <> "" And _
  19. me.URL <> "" Then
  20.  
  21. Return True
  22.  
  23. Else
  24.  
  25. Return False
  26.  
  27. End If
  28.  
  29. End Function
  30.  
  31. Public Function ToSmallListViewItem() As ListViewItem
  32.  
  33. Dim item As New ListViewItem
  34.  
  35. item.SubItems.Add(me.State)
  36. item.SubItems.Add(me.Name)
  37. item.Tag = Me
  38.  
  39. Return item
  40.  
  41. End Function
  42.  
  43. End Class

From the last member function you can guess that I want to display lists of instances of this class in a listview control. Here is the code. It is a member of the main form of the application that owns the listview

  1.  
  2. Private Sub LoadMasterCityList()
  3.  
  4. lvMasterCityList.Items.Clear()
  5.  
  6. 'master cities is an element of a wrapper class for List(Of City)
  7. 'even when I bypass the wrapper and deal directly with the list as below
  8. 'it doesn't work
  9.  
  10. MasterCities = Cities.Load(Settings.strMasterCityListFile) 'this just loads from a file
  11. For Each CityItem As City In MasterCities.CityList
  12.  
  13. 'this is the listview control
  14. lvMasterCityList.Items.Add(CityItem.ToSmallListViewItem())
  15.  
  16. Next


The problem is that the listview doesn't display the input. It has two columns as required by [inlinecode=vb]City.ToSmallListViewItem()[/inlinecode] method and is set to visible. It creates a scrollbar and I can highlight empty elements of it and scroll around. I just cant see the text. I am positive that the data is valid as it is sent to the [inlinecode=vb]LoadMasterCityList[/inlinecode] method, for example I have used [inlinecode=vb]MsgBox[/inlinecode]'s to print the contents of each [inlinecode=vb]CityItem[/inlinecode] both before and after the call to [inlinecode=vb]CityItem.ToSmallListViewItem()[/inlinecode] so I am sure that the data is write. Does anyone have any idea what can cause this behavior? I am stumped! All I have been able to find is that setting the checkbox property to true can cause a listbox too not render but I am not doing that and that is only applicable if its in large image or small image mode. It's in list mode anyway so thats not it.

Thanks in advance
Aaron
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC