Im trying to get all the items from a listview into a string like so:
foreach(ListViewItem item in ListView1.Items)
{
thisstring += item...?
}
item.Text is not a property of item...can seem to figure this out. Any suggestions?
Im trying to get all the items from a listview into a string like so:
foreach(ListViewItem item in ListView1.Items)
{
thisstring += item...?
}
item.Text is not a property of item...can seem to figure this out. Any suggestions?
You could use LINQ to select all items' Text.
var allItems = ListView1.Items.Cast<ListItem>().Select(i => i.Text);
var allItemText = String.Join(",", allItems);
Note that you need to add the System.LINQ namespace.
Edit: I've read ListBox, a ListView does not have a Text property and i'm not sure what text you actually want to concat.
StringBuilder sb = new StringBuilder();
foreach(ListViewItem item in ListView1.Items)
{
sb.Append(item.Text);
sb.Append(',');
}
Console.WriteLine(sb.ToString().TrimEnd(','));
EDIT: As Tim and Guest said, there is not Text property for ListViewItem in ASP.Net, Windows Forms has ListViewItem and it has the text property. ASP.Net ListView does not have Text property