private void CreateCellsForColumn(int insertIndex, TableColumn <T> column) { SuspendLayout(); try { List <TableCell> cells; if (_lstItems != null) { cells = new List <TableCell>(_lstItems.Count); for (int i = 0; i < _lstItems.Count; i++) { T item = _lstItems[i]; TableCell cell = CreateCell(item, column); cells.Add(cell); if (_filter(item)) { TableRow row = _lstRowCells[i]; row.SuspendLayout(); try { row.Controls.Add(cell); } finally { row.ResumeLayout(false); } } } } else { cells = new List <TableCell>(1); } HeaderCell header = new HeaderCell { Text = column.Text, TextTag = column.Tag }; if (column.Sorter != null) { header.HeaderClick += (sender, evt) => { if (_sortColumn == column) { // cycle through states if column remains the same switch (_eSortType) { case SortOrder.None: _eSortType = SortOrder.Ascending; break; case SortOrder.Ascending: _eSortType = SortOrder.Descending; break; case SortOrder.Descending: _eSortType = SortOrder.None; break; } } else { if (_sortColumn != null) { // reset old column sort arrow for (int i = 0; i < _columns.Count; i++) { if (_columns[i] == _sortColumn) { _lstCells[i].header.SortType = SortOrder.None; break; } } } _sortColumn = column; _eSortType = SortOrder.Ascending; } header.SortType = _eSortType; Sort(); }; header.Sortable = true; } Controls.Add(header); _lstCells.Insert(insertIndex, new ColumnHolder(header, cells)); } finally { ResumeLayout(false); } }
public ColumnHolder(HeaderCell header, IList <TableCell> cells) { this.header = header; this.cells = cells; }