private void FillGrid(bool doReselctRows = true) { List <long> listSelectedClinicNums = new List <long>(); if (doReselctRows) { listSelectedClinicNums = gridMain.SelectedTags <Clinic>().Select(x => x.ClinicNum).ToList(); } gridMain.BeginUpdate(); gridMain.ListGridColumns.Clear(); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableClinics", "Abbr"), 120)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableClinics", "Description"), 200)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableClinics", "Specialty"), 150)); if (!IsSelectionMode) { gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableClinics", "Pat Count"), 80, HorizontalAlignment.Center)); gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableClinics", "Hidden"), 0, HorizontalAlignment.Center)); } gridMain.ListGridRows.Clear(); GridRow row; Dictionary <long, string> dictClinicSpecialtyDescripts = Defs.GetDefsForCategory(DefCat.ClinicSpecialty).ToDictionary(x => x.DefNum, x => x.ItemName); List <int> listIndicesToReselect = new List <int>(); foreach (Clinic clinCur in ListClinics) { if (!checkShowHidden.Checked && clinCur.IsHidden) { continue; } row = new GridRow(); row.Cells.Add((clinCur.ClinicNum == 0?"":clinCur.Abbr)); row.Cells.Add(clinCur.Description); string specialty = ""; string specialties = string.Join(",", clinCur.ListClinicSpecialtyDefLinks .Select(x => dictClinicSpecialtyDescripts.TryGetValue(x.DefNum, out specialty)?specialty:"") .Where(x => !string.IsNullOrWhiteSpace(x))); row.Cells.Add(specialties); if (!IsSelectionMode) //selection mode means no IsHidden or Pat Count columns { int patCount = 0; _dictClinicalCounts.TryGetValue(clinCur.ClinicNum, out patCount); row.Cells.Add(POut.Int(patCount)); row.Cells.Add(clinCur.IsHidden?"X":""); } row.Tag = clinCur; gridMain.ListGridRows.Add(row); if (listSelectedClinicNums.Contains(clinCur.ClinicNum)) { listIndicesToReselect.Add(gridMain.ListGridRows.Count - 1); } } gridMain.EndUpdate(); if (doReselctRows && listIndicesToReselect.Count > 0) { gridMain.SetSelected(listIndicesToReselect.ToArray(), true); } }