I would stronglly reccomend, what has abelLazm proposed you, to change the event. Do not use SelectedIndexChaged, becuase you will have only problems. Use Click event.
What is the problem with SelectedIndexChnaged event is that it wires twice for the row selection. When you clik the listView for the 1st time it fires ones - thats ok, but as soon as you click it for the 2nd time, it will fire for the 1st clicked row, and for the 2nd time for the newly clicked row. So it can make your life very miserable, if oyur dont know how to handle it.
As said, use Click event and all will be fine - its the same thing.
I did an example code how to get items and subitems from lisrView:
public Form1()
{
InitializeComponent();
listView1.Columns.Add("Column1", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Column2", -2, HorizontalAlignment.Center);
listView1.View = View.Details;
listView1.FullRowSelect = true;
//add some example rows:
for (int i = 1; i < 5; i++)
{
ListViewItem lvi = new ListViewItem(i.ToString() +".");
lvi.SubItems.Add("Column 2 - " + i);
listView1.Items.Add(lvi);
}
listView1.Click += new EventHandler(listView1_Click);
}
private void listView1_Click(object sender, EventArgs e)
{
string col1 = listView1.SelectedItems[0].Text;
string col2 = listView1.SelectedItems[0].SubItems[1].Text;
MessageBox.Show("1st column: " + col1 + "\n2nd column: " + col2);
}