public int FindIndex(TableColumn column) { return(items.FindIndex(x => x == column)); }
public virtual void Sort(TableColumn column, ListSortDirection direction) { if (column == null) { return; } int columnIndex = Columns.FindIndex(column); Dictionary <TableRow, object[]> items = new Dictionary <TableRow, object[]>(); for (int i = 0; i < Rows.Count; i++) { var r = Rows[i]; items.Add(r, r.Items); } var itemsList = items.ToList(); if (direction == ListSortDirection.Ascending) { itemsList.Sort((x, y) => { var v1 = x.Value[columnIndex]; var v2 = y.Value[columnIndex]; if (v1 == null && v2 == null) { return(0); } if (v1 == null) { return(-1); } if (v2 == null) { return(1); } var we = v1.ToString().CompareTo(v2.ToString()); return(we); }); } else { itemsList.Sort((x, y) => { var v1 = x.Value[columnIndex]; var v2 = y.Value[columnIndex]; if (v1 == null && v2 == null) { return(0); } if (v1 == null) { return(1); } if (v2 == null) { return(-1); } var we = v1.ToString().CompareTo(v2.ToString()); return(-we); }); } Rows.ClearList(); for (int i = 0; i < itemsList.Count; i++) { Rows.Add(itemsList[i].Key); } AlignRows(); if (lastSortedColumn != null) { lastSortedColumn.control.Padding = new Padding(8, 0, 8, 0); } lastSortedColumn = column; lastSortedColumn.control.Padding = new Padding(24, 0, 8, 0); }
public void Add(TableColumn column) { items.Add(column); }