loops

Im a bit new to loops. Can anyone explain to me how its possible to use a loop to move items from a listbox to a textbox one item at a time(a confirmation message box will be displayed) what kind of loop is best for this

Answer this question

loops

  • Thanh Nguyen


    for( int i = 0; i < listBox.Items.Count; i++)
    {
     // Lett the user confirm this action.
        if( MessageBox.Show( this, "Are you sure you want to move " + listBox.Items[ i ].ToString() + " ",
            Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes )
        {
      // Add item to other listbox and remove from current.
            lstDestinationListBox.Items.Add( listBox.Items[ i ] );
            listBox.Items.RemoveAt( i );
           
            // Lower i with 1, so the new item on the index will be processed as well.
            i--;
        }
    }

     



  • rw72000

    Thanks alot!
  • loops