Example #1
0
 // not supporting multi select for now
 protected override bool CanMultiSelect(TreeViewItem item) => false;
Example #2
0
        protected override IList <TreeViewItem> BuildRows(TreeViewItem root)
        {
            var items = new List <TreeViewItem>();

            for (int i = 0; i < _data.Count; i++)
            {
                items.Add(new RowData(i, _data[i]));
            }

            var sortedColumns = multiColumnHeader.state.sortedColumns;

            if (sortedColumns.Length > 0)
            {
                items.Sort((baseA, baseB) => {
                    var a = baseA as RowData;
                    var b = baseB as RowData;
                    if (a == null)
                    {
                        return(1);
                    }
                    if (b == null)
                    {
                        return(-1);
                    }
                    // sort based on multiple columns
                    foreach (var column in sortedColumns)
                    {
                        bool ascending = multiColumnHeader.IsSortedAscending(column);
                        // flip for descending
                        if (!ascending)
                        {
                            var tmp = b;
                            b       = a;
                            a       = tmp;
                        }
                        int compareResult = 0;

                        var aVal = GetColumnValue(a, column) as IComparable;
                        var bVal = GetColumnValue(b, column) as IComparable;
                        if (aVal != bVal)
                        {
                            if (aVal == null)
                            {
                                compareResult = 1;
                            }
                            else if (bVal == null)
                            {
                                compareResult = -1;
                            }
                            else
                            {
                                compareResult = aVal.CompareTo(bVal);
                            }
                        }
                        // not equal in this column, then return that
                        if (compareResult != 0)
                        {
                            return(compareResult);
                        }
                    }
                    return(a.id.CompareTo(b.id));
                });
            }

            return(items);
        }