private List<List<CodeVM>> SplitCodes(List<CodeVM> validCodes, ChoicesLayoutVM choicesLayout) { List<List<CodeVM>> codesList = new List<List<CodeVM>>(); int count = GetSplitCount(choicesLayout); int countPerArea = DivideCeil(validCodes.Count, count); if (choicesLayout.Direction == ChoicesLayoutDirection.Vertical) { List<CodeVM> codesPerArea = null; int i = 0; foreach (CodeVM code in validCodes) { if (i % countPerArea == 0) { codesPerArea = new List<CodeVM>(); codesList.Add(codesPerArea); } codesPerArea.Add(code); i++; } } else { int areaCount = DivideCeil(validCodes.Count, countPerArea); //これがセルの数になる for (int j = 0; j < areaCount; j++) { codesList.Add(new List<CodeVM>()); } int i = 0; //列を順番に入れ替えながらうめていく。 foreach (CodeVM code in validCodes) { int codesIndex = i % areaCount; codesList[codesIndex].Add(code); i++; } } return codesList; }
private int GetSplitCount(ChoicesLayoutVM choicesLayout) { int count = 1; if (choicesLayout.ColumnCount != null && choicesLayout.ColumnCount.HasValue) { count = choicesLayout.ColumnCount.Value; } return count; }