Hi, I have a few questions which I need answering please.
I have a ListView and I need to get the text in the cell which is clicked. At the moment i have this but it only works for the first cell which is clicked and throws an ArgumentOutOfRangeException if I click any more.
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(listView1.SelectedItems[0].SubItems[0].Text.ToString());
for (int i = 0; i < programmes.Count; i++)
{
if (listView1.SelectedItems[0].SubItems[0].Text.ToString().Equals(programmes[i].Title))
{
MessageBox.Show("Title: " + programmes[i].Title + "\nStart Date: " + programmes[i].Start_d + "\nStart Time: " + programmes[i].Start_t +
"\nEnd Time: " + programmes[i].End_t + "\nChannel: " + getChannel() + "\nRepeat: " + programmes[i].Repeat);
break;
}
}
}
Someone suggested using linq but I get the same error.
Secondly, what is the correct way to populate a ListView? At the moment i have this:
for (int i = 0; i < programmes.Count(); i++)
{
string[] arr = { programmes[i].Start_t.TimeOfDay.ToString(), programmes[i].End_t.TimeOfDay.ToString(), programmes[i].Repeat };
listView1.Items.Add(programmes[i].Title).SubItems.AddRange(arr);
}
}
It works but its slightly annoying, Thanks.