List items are not displayed

Is there a reason why when using listview1.View = View.Details my list will expand (generate scrollbars) when adding elements, but have them invisible, but when I switch it to listview1.View = View.List , it works fine ?

I don't think this is really important, but here is the code I use to add items to the list:

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

And the code of the auto-generated designer:

  // // 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 containing about 50 odd characters in the first element (checked using the debugger).

+7
source share
5 answers

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 this is not so, I have no idea. Are the characters of the added string visible?

+16
source

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

+44
source

You need to add a column to view the details.

+9
source

I had the same problem with invisible text in my listview . The error was made by me when I cloned an element using code; I accidentally renamed only the first part and again added textual information to the first elements, but not to the cloned elements. Here is what I mean:

Wrong:

 ListViewItem item_klon2 = new ListViewItem(); item_klon.Text = System.IO.Path.GetFileName(file_with_path); item_klon.SubItems.Add(short_date); item_klon.SubItems.Add(filesize.ToString() + " kb"); 

On right:

 ListViewItem item_klon2 = new ListViewItem(); item_klon2.Text = System.IO.Path.GetFileName(file_with_path); item_klon2.SubItems.Add(short_date); item_klon2.SubItems.Add(filesize.ToString() + " kb"); 
+1
source

I had the same problem.

I set the column width to -2 so that it automatically changes the length of the text in the column heading. When I switched to the Details view, the column width was automatically reset to 0, thereby hiding the elements.

0
source

Source: https://habr.com/ru/post/889020/


All Articles