title: How to ignore overselect in listbox
body: <p>Currently I have 6 listbox. Im trying to select all 5 other listbox items in the same row as the one manually selected. </p>
  
  <p>However, Im getting an error : </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.StackOverflowException'
    occurred in System.Windows.Forms.dll</p>
    
    <p>Cannot evaluate expression because the current thread is in a stack
    overflow state.</p>
  </blockquote>
  
  <p>Below is an example of code for one of the listbox, repeated for all other listbox.</p>
  
  <p>private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
          {</p>
  
  <pre><code>      listBox1.SelectedIndexChanged=1;
          listBox3.SelectedIndex = -1;
          listBox2.SelectedIndex = -1;
          listBox4.SelectedIndex = -1;
          listBox5.SelectedIndex = -1;
          listBox6.SelectedIndex = -1;
          listBox2.ClearSelected();
         listBox3.ClearSelected();
         listBox4.ClearSelected();
         listBox5.ClearSelected();
         listBox6.ClearSelected();
         int  a = listBox1.SelectedIndex;
         int b = listBox2.SelectedIndex;
         int c = listBox3.SelectedIndex;
         int d = listBox4.SelectedIndex;
         int f = listBox5.SelectedIndex;
         int g = listBox6.SelectedIndex;
  
  
          if (a &gt;-1)
          {
             // listBox1.SetSelected(a,true);
              listBox2.SetSelected(a, true);
              listBox3.SetSelected(a, true);
              listBox4.SetSelected(a, true);
              listBox5.SetSelected(a, true);
              listBox6.SetSelected(a, true);
          }
          else if (b &gt; -1)
          {
              listBox1.SetSelected(b, true);
             // listBox2.SetSelected(b, true);
              listBox3.SetSelected(b, true);
              listBox4.SetSelected(b, true);
              listBox5.SetSelected(b, true);
              listBox6.SetSelected(b, true);
          }
          else if (c &gt; -1)
          {
              listBox1.SetSelected(c, true);
              listBox2.SetSelected(c, true);
           //   listBox3.SetSelected(c, true);
              listBox4.SetSelected(c, true);
              listBox5.SetSelected(c, true);
              listBox6.SetSelected(c, true);
          }
          else if (d &gt; -1)
          {
              listBox1.SetSelected(d, true);
              listBox2.SetSelected(d, true);
              listBox3.SetSelected(d, true);
            //  listBox4.SetSelected(d, true);
              listBox5.SetSelected(d, true);
              listBox6.SetSelected(d, true);
          }
          else if (f &gt; -1)
          {
              listBox1.SetSelected(f, true);
              listBox2.SetSelected(f, true);
              listBox3.SetSelected(f, true);
              listBox4.SetSelected(f, true);
             // listBox5.SetSelected(f, true);
              listBox6.SetSelected(f, true);
          }
          else if (g &gt; -1)
          {
              listBox1.SetSelected(g, true);
              listBox2.SetSelected(g, true);
              listBox3.SetSelected(g, true);
              listBox4.SetSelected(g, true);
              listBox5.SetSelected(g, true);
             // listBox6.SetSelected(g, true);
          }
  
  
      }
  
  
      private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
      {
          listBox1.SelectedIndex = -1;
          listBox3.SelectedIndex = -1;
          listBox4.SelectedIndex = -1;
          listBox5.SelectedIndex = -1;
          listBox6.SelectedIndex = -1;
          listBox1.ClearSelected();
          listBox3.ClearSelected();
          listBox4.ClearSelected();
          listBox5.ClearSelected();
          listBox6.ClearSelected();
          int a = listBox1.SelectedIndex;
          int b = listBox2.SelectedIndex;
          int c = listBox3.SelectedIndex;
          int d = listBox4.SelectedIndex;
          int f = listBox5.SelectedIndex;
          int g = listBox6.SelectedIndex;
  
  
          if (a &gt; -1)
          {
              // listBox1.SetSelected(a,true);
              listBox2.SetSelected(a, true);
              listBox3.SetSelected(a, true);
              listBox4.SetSelected(a, true);
              listBox5.SetSelected(a, true);
              listBox6.SetSelected(a, true);
          }
          else if (b &gt; -1)
          {
              listBox1.SetSelected(b, true);
              // listBox2.SetSelected(b, true);
              listBox3.SetSelected(b, true);
              listBox4.SetSelected(b, true);
              listBox5.SetSelected(b, true);
              listBox6.SetSelected(b, true);
          }
          else if (c &gt; -1)
          {
              listBox1.SetSelected(c, true);
              listBox2.SetSelected(c, true);
              //   listBox3.SetSelected(c, true);
              listBox4.SetSelected(c, true);
              listBox5.SetSelected(c, true);
              listBox6.SetSelected(c, true);
          }
          else if (d &gt; -1)
          {
              listBox1.SetSelected(d, true);
              listBox2.SetSelected(d, true);
              listBox3.SetSelected(d, true);
              //  listBox4.SetSelected(d, true);
              listBox5.SetSelected(d, true);
              listBox6.SetSelected(d, true);
          }
          else if (f &gt; -1)
          {
              listBox1.SetSelected(f, true);
              listBox2.SetSelected(f, true);
              listBox3.SetSelected(f, true);
              listBox4.SetSelected(f, true);
              // listBox5.SetSelected(f, true);
              listBox6.SetSelected(f, true);
          }
          else if (g &gt; -1)
          {
              listBox1.SetSelected(g, true);
              listBox2.SetSelected(g, true);
              listBox3.SetSelected(g, true);
              listBox4.SetSelected(g, true);
              listBox5.SetSelected(g, true);
              // listBox6.SetSelected(g, true);
          }
  </code></pre>
  
  <p>}</p>