I've got a Listview with 4 colums. I constructed the following code from examples over the net.
When I click the button it gives me ListViewItem: {Name of the car here, the first column}.
How can I get the subitems, in my case the Owner, Type etc.
How can I get the subitems, in my case the Owner, Type etc.
If you can help, please use my code if possible.
By the way, the way the selected item is displayed is that the only column that gets "blue" is the first one.
How could I make the whole row "blue"?
How could I make the whole row "blue"?
Code Code Code Code Code Code |
Thank you

Posted Oct 15, 2010, 2:49 AM EDT
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Controls/Q_10256652.html
http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.forecolor.aspx
http://www.vbforums.com/showthread.php?t=231157
Try the following code.
ListView.SelectedListViewItemCollection sel = listView1.SelectedItems;
foreach (ListViewItem item in sel)
{
foreach (ListViewItem subitem in item.SubItems)
{
MessageBox.Show(subitem.Text);
}
}
Moose Pickard64 reputationPosted Oct 15, 2010, 4:06 AM EDT
But the code you suggested gives me the following error:
InvalidCastException was unhandled
Unable to cast object of type 'ListViewSubItem' to type 'System.Windows.Forms.ListViewItem'.
Also what I said earlier about coloring the list.
I meant that the whole row would be selected when I select, not just the first item.
Thank you for the links
Moose Pickard64 reputationPosted Oct 15, 2010, 7:33 AM EDT
I changed:
foreach (ListViewItem subitem in item.SubItems)
TO
foreach (ListViewItem.ListViewSubItem subitem in item.SubItems)
But I'm wondering how could I get a specific subitem only, say for example column 2.
Does ItemView usese array or list as a collection?
I can use this Items[index], so this could be an array.
Moose Pickard64 reputationPosted Oct 15, 2010, 8:26 AM EDT
I got the selected item using:
int index = item.Index;
String item_select_ID = listView.Items[index].SubItems[3].Text;