Stop for each Loop in grid

Once a row matches an invoice number I want the for each loop to stop. How do I stop the loop?

	private void gridInvoiceEntryGrid_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs args)
	{
		UltraGridRow activeRow = gridInvoiceEntryGrid.ActiveRow;
		neInvoiceNumberfromMemos.Value = activeRow.Cells["InvcHead_InvoiceNum"].Value.ToString();
		foreach (UltraGridRow row in this.grdList.Rows.GetRowEnumerator(GridRowType.DataRow, null, null))
		{

		if (Int32.Parse(row.GetCellValue("InvoiceNum").ToString()) == Int32.Parse(neInvoiceNumberfromMemos.Value.ToString()))
			{
				MessageBox.Show("Invoice Number matches");
				row.Selected = true;
				row.Activated = true;
				gridCustomerNotes.Focus();	
			//STOP FOR EACH LOOP HERE
			}
			else
			{			
			MessageBox.Show("Invoice Number doesn't match");
			}
		}

	}

Add a line

break;

Where everything you want to happen in the loop has been done.

1 Like

And another source of info on the Break statement (My favorite source): C# break Statement - Dot Net Perls