// Check if we should rename ALL rows DataGridViewRowCollection rows; if (renameAll) { rows = dataGridView1.Rows; } else { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { rows.Add(row); } } // Begin renaming! foreach (DataGridViewRow row in rows) { // Keys: // 0 = FullPath // 1 = Song Key // 2 = BPM // 3 = Collection // --- [snip] }