So I have a ListView and I want to get the Selected Item's value and compare it to anothre string when the item is selected:
It works beautifully, but there's one probelm, it throws an exception if i click on the ListView a second time around and third and so on. It'll still do what it's supposed to, but throw an exception after the first time it's clicked on. What gives?
C#:
private void lstAccounts_SelectedIndexChanged(object sender, System.EventArgs e)
{
XmlElement Root = this.XmlDoc["accounts"];
foreach ( XmlElement account in Root.GetElementsByTagName( "account" ) )
{
if ( this.lstAccounts.SelectedItems[0].Text == account["username"].InnerText )
{
this.txtUsername.Text = account["username"].InnerText;
this.txtPassword.Text = account["password"].InnerText;
this.lstAccess.SelectedItem = account["accessLevel"].InnerText;
}
}
}
It works beautifully, but there's one probelm, it throws an exception if i click on the ListView a second time around and third and so on. It'll still do what it's supposed to, but throw an exception after the first time it's clicked on. What gives?
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.