private void fillCells(String nameQueryS, String cfQueryS) { int indexRow = 0;//just to know at which row we must write this.Patients.Rows.Clear(); //for each patient, for each visit, write information for (int i = 0; i < ps.Count; i++) { Patient thisP = ps[i]; String thisName = thisP.getName() + " " + thisP.getSurname(); String thisCf = thisP.getCF(); //MessageBox.Show("thisName: |" + thisName + "| vs |" + nameQueryS + "|" ); if (cfQueryS.ToUpper() == thisCf.ToUpper() || strContains(nameQueryS.ToUpper(), thisName.ToUpper()) || strContains(thisName.ToUpper(), nameQueryS.ToUpper()) || (nameQueryS == "" && cfQueryS == "")) { this.Patients.Rows.Add();//add a row this.Patients.Rows[indexRow].Cells[1].Value = thisP.getId(); this.Patients.Rows[indexRow].Cells[2].Value = thisName; this.Patients.Rows[indexRow].Cells[3].Value = thisCf; indexRow++; } } }