title: how can i extract the index of subitems in a listview?
body: <p>im trying to pass an item from a listview1 to another listview2 and i want to check if the selected item is still not present in listview2. im trying to use a for loop to get each index of listview2 and compare it to the item selected in listview1. i tried using this but an error says that value of 0 is not a valid index.</p>
  
  <pre><code>private void listView1_DoubleClick(object sender, EventArgs e)
  {
      bool test = true;
      for (int i = 0; i &lt; listView1.Items.Count; i++)
      {
          string ls = listView2.Items[i].SubItems[0].Text;
          string ps = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text;
          if (ls.Trim() == ps.Trim())
          {
              test = false;
          }
      }
      if (test == true)
      {
          ListViewItem ty = new ListViewItem(listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text);
          ty.SubItems.Add(listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text);
          listView2.Items.AddRange(new ListViewItem[] { ty });
      }
      else
      {
          MessageBox.Show("Student is already present in the list.","Cannot add to list",MessageBoxButtons.OK,MessageBoxIcon.Hand);
      }
   }
  </code></pre>
  
  <p>figured it out just as suggested. i used the foreach statement</p>
  
  <pre><code>private void listView1_DoubleClick(object sender, EventArgs e)
  {
   bool test = true;
   string ps = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text;           
   foreach(ListViewItem disitem in listView2.Items)
   {
    string ls = disitem.SubItems[0].Text;
    if (ps.Trim() == ls.Trim())
    {
    test = false;
    }}
    if (test == true)
    {
    ListViewItem ty = new ListViewItem(listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text);                ty.SubItems.Add(listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text);
    listView2.Items.AddRange(new ListViewItem[] { ty });
    }
    else
    {
    MessageBox.Show("Student is already present in the list.","Cannot add to list",MessageBoxButtons.OK,MessageBoxIcon.Hand);
    }}
  </code></pre>