Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listview items not showing

Tags:

c#

listview

Is there a reason why when using listview1.View = View.Details my listview will expand (generate scrollbars) when I add items but have them be invisible, but when I switch it over to listview1.View = View.List it works just fine?

Not that I think that it really matters, but here is the code that I use to add items to the listview:

     ListViewItem item1 = new ListViewItem(file[1]);
     listView1.Items.Add(item1);

And the autogenerated designer code:

        // 
        // listView1
        // 
        this.listView1.CheckBoxes = true;
        this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.Path});
        this.listView1.Location = new System.Drawing.Point(12, 44);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(457, 354);
        this.listView1.TabIndex = 7;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.Details;

file is a string array that contains about 50 odd characters in the first element (checked using debugger).

like image 390
soandos Avatar asked May 25 '11 16:05

soandos


3 Answers

Are you calling "Clear"? If so make sure you are calling lv.Items.Clear() and not lv.Clear().

like image 66
Samurai Avatar answered Nov 18 '22 01:11

Samurai


The following code should work:

ColumnHeader columnHeader1=new ColumnHeader();
columnHeader1.Text="Column1";
this.listView1.Columns.AddRange(new ColumnHeader[] { columnHeader1 });
ListViewItem item = new ListViewItem("1");
this.listView1.Items.Add(item);
this.listView1.View = View.Details;

If it doesn't I have no clue. Are the characters of the string you are adding visible?

like image 34
InBetween Avatar answered Nov 18 '22 01:11

InBetween


You need to add a column for Details view to work.

like image 25
SLaks Avatar answered Nov 18 '22 01:11

SLaks