private void Button1_Click(object sender, EventArgs e) { const string message = "Are you confirm to register the parcel? "; const string caption = "Register Online Pick up parcel"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); // If the no button was pressed ... if (result == DialogResult.No) { // will auto close } else { List<int> list = new List<int>(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == true) { list.Add(Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value)); } } ParcelController.RegisterOnlinePickUp(list, branchId); MessageBox.Show("Added Successful"); ViewOnlinePickUpRequest(); } }