No items displayed in Listview

H

H2Os

Hi

I have a ListView control into which I am adding a number of items with
additional data held in subitems. With the ListView, you cannot have
subitems without column headers so I am adding these also.

For View styles of LargeIcons, SmallIcons and Details, everything is OK -
but for List style no items are displayed.

If I remove the column headers, everything is fine except that I cannot
store the additional information.

Does anybody have any ideas or suggestions to how I can fix this?

I'm using VS.2003, CF 1.0 SP3

---Snippet---
Me.lstProducts = New System.Windows.Forms.ListView
Me.lstProducts.View = View.List
Me.lstProducts.Columns.Add("Product", -1, HorizontalAlignment.Left)
Me.lstProducts.Columns.Add("ID", 0, HorizontalAlignment.Left)
Me.Controls.Add(Me.lstProducts)

Me.general_lstProducts.Items.Clear()
lookup_dt = {DataTable}
For Each dr In lookup_dt.Select
li = New ListViewItem(dr("Description").ToString)
li.SubItems.Add(dr("ID").ToString)
Me.general_lstProducts.Items.Add(li)
li = Nothing
Next dr


Thanks in advance
 
F

Fabien

Hi,

I had the same problem and used details mode and everything is OK. Why
don't you use details mode?

Fabien Decret
 
H

H2Os

Because I don't want the additional details displayed - the ID is a GUID and
most users wouldn't want to see that! Setting the column width to 0, the
user can still resize the column and see the data - unless I can hide the
column headers?

At the moment I am using SmallIcons mode which is working OK even without an
icon. But, I wanted to find out if it was just me or if this was another
'design feature' of the CF.

Is it fixed in v2?
 
J

Joseph Byrns

You should create a new ListViewItemWithTag class, which inherits
ListViewItem and use that so:

Dim LVI as new ListViewItemWithTag(Items, TheGUID)
TheListView.Items.Add(LVI)

then when you want the Guid of a paricular ListViewItem it is just

Dim LVGUDI AS GUID = ctype(TheSelectedListViewItem.Tag, GUID)

''list view item with a tag property to contain the hidden data
Class ListViewItemWithTag
Inherits ListViewItem

Private m_tag As Object

Public Property Tag()
Get
Return m_tag
End Get
Set(ByVal Value)
m_tag = Value
End Set
End Property

Sub New(ByVal Items() As String, ByVal Tag As Object)
MyBase.New(Items)
Me.m_tag = Tag
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top