Modify as fallows
if (dataGridView1.Rows[i].Cells["OctroiCode"].Value == null)
{
MessageBox.Show("Please select octroi Code");
dataGridView1.Rows[i].Cells["OctroiCode"].Selected = true;
return;
}
The main problem is return line where your function execution get ended.