Member Avatar for Member #956757

I added a ListView object, added few Columns, but the problem is there that I can't add no text to the other columns by making new Items

Any help?

Dani AI

Generated

Both replies by and point in the right direction: extra columns in a WinForms ListView are shown as the ListViewItem’s subitems, but that only appears when the control is in Details view and proper column headers exist. The left-most column displays the ListViewItem.Text; the remaining columns come from the item’s SubItems collection. (learn.microsoft.com)

Quick troubleshooting checklist (most common causes when only the first column shows):

  • Confirm the ListView.View is set to Details and that ColumnHeader objects have been added (headers must exist to see detail columns). (learn.microsoft.com)
  • Make sure column widths aren’t zero or collapsed (ColumnHeader.Width can be set or auto-resized). (learn.microsoft.com)
  • If VirtualMode = True the control expects data from RetrieveVirtualItem; manually adding to Items won’t show rows unless virtual callbacks are implemented. (learn.microsoft.com)
  • Verify the project uses WinForms ListView (System.Windows.Forms) and not WPF’s ListView (different API). (learn.microsoft.com)

Small, safe pattern to use when populating many rows (example uses methods not shown above — keep UI updates suspended while filling):

' VB.NET (WinForms) — set details mode and suspend updates
ListView1.View = View.Details
ListView1.BeginUpdate()
' ... create ListViewItem instances and add subitems (or use AddRange) ...
ListView1.EndUpdate()

Using SubItems.AddRange lets multiple subitems be appended in one call when convenient. (learn.microsoft.com)

Notes: SubItems indexing can be confusing — SubItems(0) corresponds to the item itself; the first “real” subitem is SubItems(1). If a code path writes SubItems by index, ensure the subitem exists (add a placeholder subitem first if needed). (learn.microsoft.com)

Summary: set View to Details, confirm headers/widths, check VirtualMode and namespace, and populate subitems (AddRange is handy); use BeginUpdate/EndUpdate for bulk inserts. These steps resolve the vast majority of “only first column visible” cases.

Recommended Answers

All 2 Replies

Are you trying to add multiple cells in a single row?

Dim lvi As New ListViewItem

With lvi
    .Text = "Column1"
    .SubItems.Add("Column2")
    .SubItems.Add("Column3")
    .SubItems.Add("Column4")
End With

ListView1.Items.Add(lvi)

If you are wanting to add a column to the listview try:

ListView1.Columns.Add("ColumnName")

You can add items more concisely by

ListView1.Items.Add(New ListViewItem({"Column1","Column2","Column3",Column4"}))
commented: Clear n' Concise! +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.