public Category getValuesAsCategory(CategoryFilter cf) { string text = this.textBoxTitle.Text; List <Participant> participants = new List <Participant>(); foreach (DataGridViewRow row in (IEnumerable)this.dataGridViewParticipants.Rows) { if (row.Cells["FullName"].Value != null && row.Cells["Team"].Value != null) { int id = 0; if (row.Cells["id"].Value != null) { id = Convert.ToInt32(row.Cells["id"].Value.ToString()); } string name = row.Cells["FullName"].Value.ToString(); string team = row.Cells["Team"].Value.ToString(); Participant participant = new Participant(); participant.setName(name); participant.setTeam(team); if (id > 0) { participant.setId(id); } participants.Add(participant); } } return(new Category(text, participants, cf)); }