Listview onclick

A

Alan T

private void lvUsersList_Click(object sender, EventArgs e)

{

int userId;

ListViewItem lvi;

if (lvUsersList.SelectedItems.Count > 0)

{

lvi = lvUsersList.SelectedItems[0];

userId = Convert.ToInt32(lvi.Tag.ToString());

MessageBox.Show("User id: " + userId.ToString());

}


}



I have 2 items on a listview and would like to dispaly the id of the user.

I got no problem when I click at the first time, but got exception when I
click the second time.

The exception is:

"InvalidArgument=Value of '0' is not valid for 'index'

Parameter name: index"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top