I have a listview with 4 columns...How do I retrieve a value that I already have in the columns 3 & 4 to a label??

Dani AI

Generated

This thread effectively shows the simple, item/subitem approach that works for a Windows Forms ListView, and it also exposes a common ambiguity: there are two different controls called "ListView" (WinForms vs ASP.NET) and each requires a different retrieval pattern. pointed toward the WinForms method; the notes below expand on that and on the correct server-side approach for the Web ListView.

For a Windows Forms ListView: read values from the selected row rather than assuming an index is always valid. Confirm a selection exists, check the selected ListViewItem has enough subitems before reading, and enable FullRowSelect/Details view so selection behaves as expected. Consider storing important IDs or values in the ListViewItem.Tag to avoid brittle reliance on column order. Reference: ListView.SelectedItems, ListViewItem.SubItems, ListViewItem.Tag, ListView.FullRowSelect.

For an ASP.NET templated ListView: retrieve values in the server event model (for example in ItemDataBound or via an ItemCommand handler) by locating controls inside the item template with FindControl, or expose keys with DataKeyNames/DataKeys so the server can read the underlying value without parsing displayed text. Reference: ListView.ItemDataBound, Control.FindControl, ListView.DataKeyNames.

Quick checklist: confirm which ListView is in use (WinForms vs Web), make sure a row is actually selected, guard against out-of-range subitem access, and prefer reading the underlying data or a stored Tag/DataKey rather than relying on visible column order.

label.text = listview.items(index).subitems(column).text

The index is the line number, and colum is the item you want to retrieve ... both are 0 based.

The index is the line number, and colum is the item you want to retrieve ... both are 0 based.

Thank you

Could you please be more specific...

thanks

to retrieve item from column 4 on line 1 of the list ....

label.text = listview.items(0).subitems(3).text

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.