ba272
asked on
Trying to get a ListViewItem with a given value
Hi,
I populated the ListView with driverLabel strings. And now I'd like to get the ListViewItem with a given matching string. But Items.IndexOf() return -1 even though I know it's been added. Am I missing anything obvious?
Thanks,
Bob
string driverLabel = driverRun.Driver.DriverLab el;
if ( driverLabel != null && driverLV.Items.Count > 0 )
{
int driverLabelIndex = driverLV.Items.IndexOf(new ListViewItem(driverLabel)) ;
if ( driverLabelIndex > -1 && driverLabelIndex < driverLV.Items.Count )
{
driverRunsLV.Items[driverR unIndex].S elected = true;
}
}
I populated the ListView with driverLabel strings. And now I'd like to get the ListViewItem with a given matching string. But Items.IndexOf() return -1 even though I know it's been added. Am I missing anything obvious?
Thanks,
Bob
string driverLabel = driverRun.Driver.DriverLab
if ( driverLabel != null && driverLV.Items.Count > 0 )
{
int driverLabelIndex = driverLV.Items.IndexOf(new
if ( driverLabelIndex > -1 && driverLabelIndex < driverLV.Items.Count )
{
driverRunsLV.Items[driverR
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
foreach (ListViewItem item in this.listView1.Items)
Not
foreach (ListViewItem item in this.listView1.Items.Index
Cheers,
Aaron
http://geekswithblogs.net/afeng/