ListView problem

Hi,
i have tabcontrol containing two tabPages. One of the tabPage contains a ListView with dock property set to FILL. if i leave the default view for the ListView.view property alone, i see the items i added (though not the way i want them to appear), but if i change the view to DETAIL, i see nothing. Anyone have any idea why this is happening?

so if i have:


this.ctlLv.View = View.Details;

ListViewItem lvi =new ListViewItem( "Dell" );
ListViewSubItem lvs =new ListViewSubItem( );
lvs.Text = "Dell Corp";
lvi.SubItems.Add( lvs );

ctlLv.Items.Add( lvi );

i do not see anything in the list view. but if i comment out the first line, i do.

[990 byte] By [farseer] at [2008-2-10]
# 1

please not also, although i have not shown it in the code snippet above, i am adding the columns using ColumHeader object and calling ctlLV.columns.add( columnHeader).

I am trying this in Visual Studio 2005 beta 2

farseer at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 2

Did you set your ColumnHeader width? Because if the ColumnHeader width is 0 you won't see your item as well. You can try to resize the ColumnHeader and see if you can see the list view item.

I've tried the following code and it display the listview item correctly.

private void Form1_Load(object sender, EventArgs e)
{

this.listView1.View = View.Details;
ListViewItem lvi = new ListViewItem("Dell");
ListViewItem.ListViewSubItem lvs = new ListViewItem.ListViewSubItem();
lvs.Text = "Dell Corp";
lvi.SubItems.Add(lvs);

this.listView1.Items.Add(lvi);
ColumnHeader ch = new ColumnHeader();
this.listView1.Columns.Add(ch);
ch.Width = 50;

}

DavidTSoMSFT at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 3
it appears i have to add the items first, then add the columns. i was adding the columns first before. once i switched, it worked
farseer at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 4

and upon further inspection, the reason for this order is due to a bug in my code. in my function that populates the listview,
instead of,
this.ctlLv.Clear();

i should have written,
this.ctlLv.Items.Clear();

farseer at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...