int currentvalue = dg_ingredients[e.ColumnIndex, e.RowIndex].Value.ToString().ToInt();
index = dg_ingredients.CurrentRow.Index;
if (currentvalue <= dg_ingredients.Rows.Count && (currentvalue - 1) != -1 && _previousvalue < currentvalue)
{
dg_ingredients.Rows.Insert(currentvalue, dg_ingredients.Rows[index].Cells[0].Value, dg_ingredients.Rows[index].Cells[1].Value, dg_ingredients.Rows[index].Cells[2].Value, dg_ingredients.Rows[index].Cells[3].Value, dg_ingredients.Rows[index].Cells[4].Value, dg_ingredients.Rows[index].Cells[5].Value, dg_ingredients.Rows[index].Cells[6].Value, dg_ingredients.Rows[index].Cells[7].Value);
dg_ingredients.Rows.RemoveAt(index);
}
else
{
dg_ingredients.Rows.Insert((currentvalue-1), dg_ingredients.Rows[index].Cells[0].Value, dg_ingredients.Rows[index].Cells[1].Value, dg_ingredients.Rows[index].Cells[2].Value, dg_ingredients.Rows[index].Cells[3].Value, dg_ingredients.Rows[index].Cells[4].Value, dg_ingredients.Rows[index].Cells[5].Value, dg_ingredients.Rows[index].Cells[6].Value, dg_ingredients.Rows[index].Cells[7].Value);
dg_ingredients.Rows.RemoveAt(index+1);
}