// copy a sort level
        void _btnCopyLevel_Click(object sender, RoutedEventArgs e)
        {
            var index = _flex.SelectedIndex;
            var item  = _sdc[index];
            var sd    = new UnboundSortDescription(item.Column, item.Direction);

            _sdc.Insert(index + 1, sd);
            _flex.SelectedIndex++;
        }
        /// <summary>
        /// Initializes a new instance of a <see cref="SortDialog"/>.
        /// </summary>
        public SortDialog(C1FlexGridBook owner)
            : this()
        {
            // save reference to owner grid (the one being sorted)
            _owner = owner;

            // initialize sort descriptors
            _sdc.Clear();
            var sel = _owner.Selection;

            if (sel.IsValid)
            {
                for (int c = sel.LeftColumn; c <= sel.RightColumn; c++)
                {
                    var sd = new UnboundSortDescription(_owner.Columns[c], ListSortDirection.Ascending);
                    _sdc.Add(sd);
                }
            }
            else
            {
                _sdc.Add(new UnboundSortDescription());
            }

            // update UI when the collection/selection change
            _flex.SelectionChanged += _flex_SelectionChanged;

            // add data map to "Column" column
            var col       = _flex.Columns["Column"];
            var dctColumn = new Dictionary <Column, string>();

            foreach (var c in _owner.Columns)
            {
                dctColumn[c] = GetColumnName(c);
            }
            col.ValueConverter = new ColumnValueConverter(dctColumn);

            // add data map to "Direction" column
            col = _flex.Columns["Direction"];
            var dctOrder = new Dictionary <ListSortDirection, string>();

            dctOrder[ListSortDirection.Ascending]  = "Ascending";
            dctOrder[ListSortDirection.Descending] = "Descending";
            col.ValueConverter = new ColumnValueConverter(dctOrder);

            // show sort descriptors on grid
            _flex.ItemsSource = _sdc;
        }