private void btnAdd_Click(object sender, EventArgs e) { if (searchInProgress) { DialogResult dr = MessageBox.Show(this, "Search is currently in progress, would you like to cancel it?", "Projection", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.No) { return; } else { searchThread.Abort(); probe.Abort(); } } List <string> ipAddresses = new List <string>(); for (int i = 0; i < gridIPList.Rows.Count; i++) { if (((bool)gridIPList.Rows[i].Cells[0].Value == true)) { ipAddresses.Add((string)gridIPList.Rows[i].Cells[1].Value); } } Tag = ipAddresses; Close(); }