Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView not displaying data.

Status
Not open for further replies.

steverbs

Programmer
Jul 17, 2003
253
GB
Hi all.

I am having alot of trouble getting the ListView to work. I am adding ListViewItems from a Collection of Objects (I have debugged and checked that they are being added to the ListView and they definitely are), but the data isn't showing up in the ListView. What could cause this to happen?

Here's the code:

Private Sub FrmFindContact_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.setListView()
End Sub

Private Sub setListView()
Dim collEnum As IEnumerator
Dim objQuery As New ObjectQuery(GetType(BLL.Contact), "", "")
Dim allContacts As ObjectSet = Global.Manager.GetObjectSet(objQuery)

Me.lvwContacts.Columns.Add("Name", -2, HorizontalAlignment.Left)
Me.lvwContacts.Columns.Add("Telephone", -2, HorizontalAlignment.Left)
Me.lvwContacts.Columns.Add("Email", -2, HorizontalAlignment.Left)

Me.lvwContacts.Items.Clear()

If (Not allContacts Is Nothing) Then
collEnum = allContacts.GetEnumerator()

While (collEnum.MoveNext)
Dim curContact As BLL.Contact = DirectCast(collEnum.Current, BLL.Contact)
Dim objViewItem As New ListViewItem(curContact.displayName)

objViewItem.SubItems.Add(curContact.homeTel)
objViewItem.SubItems.Add(curContact.email)
objViewItem.EnsureVisible()

Me.lvwContacts.Items.Add(objViewItem)
End While
End If
End Sub
 
Not sure, but have you checked the view property of the listview control. I normally set this to details, which shows a list of items contained within.

Simon
 
Yeah. It is set to details. Here's the initialisation code:

Me.lvwContacts.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lvwContacts.FullRowSelect = True
Me.lvwContacts.GridLines = True
Me.lvwContacts.Location = New System.Drawing.Point(12, 40)
Me.lvwContacts.Name = "lvwContacts"
Me.lvwContacts.Size = New System.Drawing.Size(588, 340)
Me.lvwContacts.TabIndex = 22
Me.lvwContacts.View = System.Windows.Forms.View.Details
 
OK. I tried changing the View setting and it works (the data displays) for every option with the exception of Details. However, I am tring to get it to display in Details mode.

Any ideas?
 
It's you column widths

Me.lvwContacts.Columns.Add("Name", -2, HorizontalAlignment.Left)
Me.lvwContacts.Columns.Add("Telephone", -2, HorizontalAlignment.Left)
Me.lvwContacts.Columns.Add("Email", -2, HorizontalAlignment.Left)

should be somthing like

Me.lvwContacts.Columns.Add("Name", 100, HorizontalAlignment.Left)
Me.lvwContacts.Columns.Add("Telephone", 100, HorizontalAlignment.Left)
Me.lvwContacts.Columns.Add("Email", 100, HorizontalAlignment.Left)


Cheers
Simon
 
Haha! Thank you. Its allways something simple. Although, I got the -2 width thing from MSDN. It is supposed to autosize the column heading. How does it work?
 
Yeah, i've seen that. Have you tried using -1 to autosize to the content text rather than the header text. If so, does that work?

Simon
 
I've tried using -1 and it does exactly the same thing. All of the columns are hidden on the left, as if they were all set to 0 width.

Thanks for the help though.

Regards.

Stephen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top