Пример #1
0
 protected virtual void OnColumnDisplayIndexChanged(DataGridColumnEventArgs e) 
 {
     EventHandler<DataGridColumnEventArgs> handler = this.ColumnDisplayIndexChanged;
     if (handler != null) 
     {
         handler(this, e);
     } 
 } 
Пример #2
0
        private void RadioMenuSortColumn_Click(object sender, RoutedEventArgs e)
        {
            DataGridColumnEventArgs args = null;

            switch ((sender as RadioMenuFlyoutItem).Tag)
            {
            case "nameColumn":
                args = new DataGridColumnEventArgs(nameColumn);
                break;

            case "dateColumn":
                args = new DataGridColumnEventArgs(dateColumn);
                break;

            case "typeColumn":
                args = new DataGridColumnEventArgs(typeColumn);
                break;

            case "sizeColumn":
                args = new DataGridColumnEventArgs(sizeColumn);
                break;

            case "originalPathColumn":
                args = new DataGridColumnEventArgs(originalPathColumn);
                break;

            case "dateDeletedColumn":
                args = new DataGridColumnEventArgs(dateDeletedColumn);
                break;

            case "dateCreatedColumn":
                args = new DataGridColumnEventArgs(dateCreatedColumn);
                break;
            }

            if (args != null)
            {
                AllView_Sorting(sender, args);
            }
        }
Пример #3
0
        private void DataGrid_Sorting(object sender, DataGridColumnEventArgs e)
        {
            // Clear previous sorted column if we start sorting a different column
            string previousSortedColumn = viewModel.CachedSortedColumn;

            if (previousSortedColumn != string.Empty)
            {
                foreach (DataGridColumn dataGridColumn in dataGrid.Columns)
                {
                    if (dataGridColumn.Tag != null && dataGridColumn.Tag.ToString() == previousSortedColumn &&
                        (e.Column.Tag == null || previousSortedColumn != e.Column.Tag.ToString()))
                    {
                        dataGridColumn.SortDirection = null;
                    }
                }
            }

            // Toggle clicked column's sorting method
            if (e.Column.Tag != null)
            {
                if (e.Column.SortDirection == null)
                {
                    dataGrid.ItemsSource   = viewModel.SortData(e.Column.Tag.ToString(), true);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else if (e.Column.SortDirection == DataGridSortDirection.Ascending)
                {
                    dataGrid.ItemsSource   = viewModel.SortData(e.Column.Tag.ToString(), false);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
                else
                {
                    dataGrid.ItemsSource   = viewModel.FilterData(DataGridDataSource.FilterOptions.All);
                    e.Column.SortDirection = null;
                }
            }
        }
Пример #4
0
        private void DataGrid_Sorting(object sender, DataGridColumnEventArgs e)
        {
            string previousSortedColumn = viewModel.CachedSortedColumn;

            if (previousSortedColumn != string.Empty)
            {
                foreach (DataGridColumn dataGridColumn in dataGrid.Columns)
                {
                    if (dataGridColumn.Tag != null && dataGridColumn.Tag.ToString() == previousSortedColumn)
                    {
                        if (e.Column.Tag == null || previousSortedColumn != e.Column.Tag.ToString())
                        {
                            dataGridColumn.SortDirection = null;
                            previousSortDirection        = null;
                        }
                    }
                }
            }

            if (e.Column.Tag != null)
            {
                if ((e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Ascending) &&
                    previousSortDirection != DataGridSortDirection.Ascending)
                {
                    dataGrid.ItemsSource   = viewModel.SortData(e.Column.Tag.ToString(), true);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                    previousSortDirection  = DataGridSortDirection.Ascending;
                }
                else
                {
                    dataGrid.ItemsSource   = viewModel.SortData(e.Column.Tag.ToString(), false);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                    previousSortDirection  = DataGridSortDirection.Descending;
                }
            }
        }
Пример #5
0
        private void OnColumnReordered(object sender, DataGridColumnEventArgs dataGridColumnEventArgs)
        {
            if (dataGridColumnEventArgs.Column == null || !(dataGridColumnEventArgs.Column is DataGridBoundColumn))
            {
                return;
            }

            Binding colBind = ((DataGridBoundColumn)dataGridColumnEventArgs.Column).Binding as Binding;

            if (colBind == null || colBind.Path == null)
            {
                return;
            }

            string field = colBind.Path.Path;

            if (String.IsNullOrWhiteSpace(field))
            {
                return;
            }

            int    displayOrder = dataGridColumnEventArgs.Column.DisplayIndex;
            string textBoxName  = getTextBoxName(field);

            TextBox textBox = (from tb in _txtSearchPanel.Children.OfType <TextBox>()
                               where tb.Name == textBoxName
                               select tb).FirstOrDefault <TextBox>();

            if (textBox == null)
            {
                return;
            }

            _txtSearchPanel.Children.Remove(textBox);
            _txtSearchPanel.Children.Insert(displayOrder, textBox);
        }
 private void DataGrid_ColumnDisplayIndexChanged(object sender, DataGridColumnEventArgs e)
 {
     _updateColumnGripperToolTipVisibilityThrottle.Tick();
 }
Пример #7
0
 private void DataGrid_Sorting(object sender, DataGridColumnEventArgs e) =>
 (sender as DataGrid).Sort(e.Column, ViewModel.Customers.Sort);
Пример #8
0
 private void dataGrid_ColumnReordered(object sender, DataGridColumnEventArgs e)
 {
     this.SaveDataGridColumnWidths();
 }
        private void dg_sorting(object sender, DataGridColumnEventArgs e)
        {
            if (e.Column.Tag.ToString() == null)
            {
                return;
            }
            // 直前に選ばれていたcollumが別ならアイコンを消しておく
            if (c != e.Column && c != null)
            {
                c.SortDirection = null;
            }

            if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Ascending)
            {
                // 選択collumが未選択・昇順状態であれば、降順にする
                e.Column.SortDirection = DataGridSortDirection.Descending;

                //選択Collumによって分岐
                if (e.Column.Tag.ToString() == "Jan")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._janCode descending select i);
                }
                else if (e.Column.Tag.ToString() == "Item")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._itemName descending select i);
                }
                else if (e.Column.Tag.ToString() == "Price")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._price descending select i);
                }
                else if (e.Column.Tag.ToString() == "Num")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._num descending select i);
                }
                else if (e.Column.Tag.ToString() == "Category")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._categoryId descending select i);
                }
            }
            else
            {
                // 選択collumが降順状態であれば、昇順にする
                e.Column.SortDirection = DataGridSortDirection.Ascending;

                //選択Collumによって分岐
                if (e.Column.Tag.ToString() == "Jan")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._janCode ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Item")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._itemName ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Price")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._price ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Num")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._num ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Category")
                {
                    dataGrid.ItemsSource = new ObservableCollection <Item>(from i in Items orderby i._categoryId descending select i);
                }
            }
            // 現在選ばれていたcollumの保持
            c = e.Column;
        }
Пример #10
0
 protected internal virtual void OnColumnReordered(DataGridColumnEventArgs e)
 {
     if (ColumnReordered != null)
     {
         ColumnReordered(this, e);
     }
 }
Пример #11
0
        private void Stock_Sorting(object sender, DataGridColumnEventArgs e)
        {
            //Use the Tag property to pass the bound column name for the sorting implementation

            if (e.Column.Tag.ToString() == "Name")
            {
                //Implement sort on the column using LINQ
                if (e.Column.SortDirection == null)
                {
                    stockList.ItemsSource = new ObservableCollection <MerchandiseModel>(from item in vm.ObsMerch
                                                                                        orderby item.ProductName ascending
                                                                                        select item);

                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else if (e.Column.SortDirection == DataGridSortDirection.Ascending)
                {
                    stockList.ItemsSource = new ObservableCollection <MerchandiseModel>(from item in vm.ObsMerch
                                                                                        orderby item.ProductName descending
                                                                                        select item);

                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
                else
                {
                    stockList.ItemsSource  = vm.ObsMerch;
                    e.Column.SortDirection = null;
                }
            }

            if (e.Column.Tag.ToString() == "Amount")
            {
                if (e.Column.SortDirection == null)
                {
                    stockList.ItemsSource = new ObservableCollection <MerchandiseModel>(from item in vm.ObsMerch
                                                                                        orderby item.Amount ascending
                                                                                        select item);

                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else if (e.Column.SortDirection == DataGridSortDirection.Ascending)
                {
                    stockList.ItemsSource = new ObservableCollection <MerchandiseModel>(from item in vm.ObsMerch
                                                                                        orderby item.Amount descending
                                                                                        select item);

                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
                else
                {
                    stockList.ItemsSource  = vm.ObsMerch;
                    e.Column.SortDirection = null;
                }
            }

            // add code to handle sorting by other columns as required

            // Remove sorting indicators from other columns
            foreach (var dgColumn in stockList.Columns)
            {
                if (dgColumn.Tag.ToString() != e.Column.Tag.ToString())
                {
                    dgColumn.SortDirection = null;
                }
            }
        }
 private void OnColumnReordering(object sender, DataGridColumnEventArgs args)
 {
     this.columnReorderingIndex = args.Column.DisplayIndex;
 }
Пример #13
0
 private void DataGrid_ColumnReordered(object sender, DataGridColumnEventArgs e)
 {
     SwagDataTable.Columns[e.Column.Header.ToString()].SetSequence(e.Column.DisplayIndex);
 }
Пример #14
0
        internal void OnMouseLeftButtonUp(ref bool handled, Point mousePosition)
        {
            if (handled)
            {
                return;
            }

            if (_dragMode == DragMode.MouseDown)
            {
               OnMouseLeftButtonUp_Click(ref handled);
            }
            else if (_dragMode == DragMode.Reorder)
            {
                // Find header we're hovering over
                int? targetIndex = this.GetReorderingTargetDisplayIndex(mousePosition, true /* ignoreVertical */, true /* clipToVisible */);

                if (targetIndex.HasValue)
                {
                    try
                    {
                        this.OwningColumn.DisplayIndex = targetIndex.Value;

                        DataGridColumnEventArgs ea = new DataGridColumnEventArgs(this.OwningColumn);
                        this.OwningGrid.OnColumnReordered(ea);
                    }
                    catch (InvalidOperationException e)
                    {
                        // we will no-op the frozen column situation, and just continue as if a cancel
                        if (e.Message != DataGridError.DataGrid.CannotMoveNonFrozenColumn().Message
                            && e.Message != DataGridError.DataGrid.CannotMoveFrozenColumn().Message)
                        {
                            throw;
                        }
                    }
                }

                DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(mousePosition.X - _dragStart.Value.X, mousePosition.Y - _dragStart.Value.Y, false);
                this.OwningGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
            }
            else if (_dragMode == DragMode.Drag)
            {
                DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(0, 0, false);
                this.OwningGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
            }

            // 
            SetDragCursor(mousePosition);

            // Variables that track drag mode states get reset in DataGridColumnHeader_LostMouseCapture
            ReleaseMouseCapture();
            handled = true;
        }
Пример #15
0
 private void TermsGrid_ColumnReordered(object sender, DataGridColumnEventArgs e)
 {
     IsSorted = true;
 }
Пример #16
0
        //DataGrid sorting stuff
        private void presetDataGrid_Sort(object sender, DataGridColumnEventArgs e)
        {
            presetDataGrid.ItemsSource = null;
            List <Tea> sortedList = new List <Tea>();

            hasSorted = true;

            //Use the Tag property to pass the bound column name for the sorting implementation
            if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
            {
                switch (e.Column.Tag.ToString())
                {
                //Implement ascending sort on the column "Range" using LINQ
                case "Name":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.Name ascending select preset);
                    break;

                case "Type":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.Type ascending select preset);
                    break;

                case "BaseSeconds":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.BaseSeconds ascending select preset);
                    break;

                case "PlusSeconds":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.PlusSeconds ascending select preset);
                    break;

                case "Temp":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.Temp ascending select preset);
                    break;

                case "MaxInfusions":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.MaxInfusions ascending select preset);
                    break;

                case "AltName":
                    break;
                }

                e.Column.SortDirection = DataGridSortDirection.Ascending;

                if (e.Column.Tag.ToString() == "AltName")
                {
                    e.Column.SortDirection = null;
                }

                //Reset all other columns
                foreach (DataGridColumn column in (sender as DataGrid).Columns)
                {
                    if (column.Tag != e.Column.Tag)
                    {
                        column.SortDirection = null;
                    }
                }
            }
            else if (e.Column.SortDirection == DataGridSortDirection.Ascending)
            {
                switch (e.Column.Tag.ToString())
                {
                //Implement ascending sort on the column "Range" using LINQ
                case "Name":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.Name descending select preset);
                    break;

                case "Type":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.Type descending select preset);
                    break;

                case "BaseSeconds":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.BaseSeconds descending select preset);
                    break;

                case "PlusSeconds":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.PlusSeconds descending select preset);
                    break;

                case "Temp":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.Temp descending select preset);
                    break;

                case "MaxInfusions":
                    sortedList = new List <Tea>(from preset in presets.Presets orderby preset.MaxInfusions descending select preset);
                    break;
                }

                e.Column.SortDirection = DataGridSortDirection.Descending;
            }

            if (e.Column.Tag.ToString() != "AltName")
            {
                presets.Presets            = null;
                presets.Presets            = sortedList;
                presetDataGrid.ItemsSource = presets.Presets;
            }

            System.GC.Collect();
        }
Пример #17
0
        private void AssociatedObject_Sorting(object sender, DataGridColumnEventArgs e)
        {
            var datas = AssociatedObject.ItemsSource as ObservableCollection <object>;

            AssociatedObject.Sort(e.Column, datas.Sort);
        }
Пример #18
0
 private void cacheList_ColumnReordered(object sender, DataGridColumnEventArgs e)
 {
     _cacheListColumnInfoCollection.UpdateFromDataGrid(cacheList);
 }
        private void DataGridColumnHeader_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (this.OwningGrid == null || this.OwningColumn == null || e.Handled || !this.IsEnabled)
            {
                return;
            }

            PointerPoint pointerPoint = e.GetCurrentPoint(this);

            if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse && pointerPoint.Properties.IsLeftButtonPressed)
            {
                return;
            }

            DataGridColumnHeaderInteractionInfo interactionInfo = this.OwningGrid.ColumnHeaderInteractionInfo;

            if (interactionInfo.DragPointerId != 0 && interactionInfo.DragPointerId != e.Pointer.PointerId)
            {
                return;
            }

            Point pointerPosition        = pointerPoint.Position;
            Point pointerPositionHeaders = e.GetCurrentPoint(this.OwningGrid.ColumnHeaders).Position;
            bool  handled = e.Handled;

            this.IsPressed = false;

            if (this.OwningGrid.ColumnHeaders != null)
            {
                switch (interactionInfo.DragMode)
                {
                case DragMode.PointerPressed:
                {
                    // Completed a click or tap without dragging, so raise the DataGrid.Sorting event.
                    InvokeProcessSort();
                    break;
                }

                case DragMode.Reorder:
                {
                    // Find header hovered over
                    int targetIndex = this.GetReorderingTargetDisplayIndex(pointerPositionHeaders);

                    if ((!this.OwningColumn.IsFrozen && targetIndex >= this.OwningGrid.FrozenColumnCount) ||
                        (this.OwningColumn.IsFrozen && targetIndex < this.OwningGrid.FrozenColumnCount))
                    {
                        this.OwningColumn.DisplayIndex = targetIndex;

                        DataGridColumnEventArgs ea = new DataGridColumnEventArgs(this.OwningColumn);
                        this.OwningGrid.OnColumnReordered(ea);
                    }

                    DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(pointerPosition.X - interactionInfo.DragStart.Value.X, pointerPosition.Y - interactionInfo.DragStart.Value.Y, false);
                    this.OwningGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
                    break;
                }

                case DragMode.Drag:
                {
                    DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(0, 0, false);
                    this.OwningGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
                    break;
                }
                }

                SetResizeCursor(e.Pointer, pointerPosition);

                // Variables that track drag mode states get reset in DataGridColumnHeader_LostPointerCapture
                if (interactionInfo.CapturedPointer != null)
                {
                    ReleasePointerCapture(interactionInfo.CapturedPointer);
                }

                this.OwningGrid.ResetColumnHeaderInteractionInfo();
                handled = true;
            }

            e.Handled = handled;

            ApplyState(true /*useTransitions*/);
        }
Пример #20
0
        public void OnSorting(object sender, DataGridColumnEventArgs e)
        {
            var dg = sender as DataGrid;

            #region Sort Number

            if (e.Column.Tag.ToString() == "Number")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Number ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Number descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort Number

            #region Sort Owned

            if (e.Column.Tag.ToString() == "Owned")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Owned ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Owned descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort Owned

            #region Sort MuseumHave

            if (e.Column.Tag.ToString() == "MuseumHave")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.MuseumHave ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.MuseumHave descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort MuseumHave

            #region Sort Price

            if (e.Column.Tag.ToString() == "Price")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Price ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Price descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort Price

            #region Sort Position

            if (e.Column.Tag.ToString() == "Position")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Position ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Position descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort Position

            #region Sort ShapOrWeather

            if (e.Column.Tag.ToString() == "ShapeOrWeather")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.ShapeOrWeather ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.ShapeOrWeather descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort ShapOrWeather

            #region Sort Time

            if (e.Column.Tag.ToString() == "Time")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Time ascending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else
                {
                    dg.ItemsSource = new ObservableCollection <NormalAnimal>(from item in Fishes
                                                                             orderby item.Time descending
                                                                             select item);
                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }

            #endregion Sort Time

            foreach (var dgColumn in dg.Columns)
            {
                if (dgColumn.Tag.ToString() != e.Column.Tag.ToString())
                {
                    dgColumn.SortDirection = null;
                }
            }
        }
        /// <summary>
        ///     Method which completes the column header drag. Includes raising of events and changing column display index if needed.
        /// </summary>
        private void FinishColumnHeaderDrag(bool isCancel)
        {
            Debug.Assert(ParentDataGrid != null, "ParentDataGrid is null");
            _prepareColumnHeaderDragging = false;
            _isColumnHeaderDragging      = false;

            _draggingSrcColumnHeader.SuppressClickEvent = false;

            if (_columnHeaderDragIndicator != null)
            {
                _columnHeaderDragIndicator.Visibility = Visibility.Collapsed;
                DataGridColumnFloatingHeader floatingHeader = _columnHeaderDragIndicator as DataGridColumnFloatingHeader;
                if (floatingHeader != null)
                {
                    floatingHeader.ClearHeader();
                }

                RemoveVisualChild(_columnHeaderDragIndicator);
            }

            if (_columnHeaderDropLocationIndicator != null)
            {
                _columnHeaderDropLocationIndicator.Visibility = Visibility.Collapsed;
                DataGridColumnDropSeparator separator = _columnHeaderDropLocationIndicator as DataGridColumnDropSeparator;
                if (separator != null)
                {
                    separator.ReferenceHeader = null;
                }

                RemoveVisualChild(_columnHeaderDropLocationIndicator);
            }

            DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(
                _columnHeaderDragCurrentPosition.X - _columnHeaderDragStartPosition.X,
                _columnHeaderDragCurrentPosition.Y - _columnHeaderDragStartPosition.Y,
                isCancel);

            ParentDataGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
            _draggingSrcColumnHeader.InvalidateArrange();

            if (!isCancel)
            {
                int  newDisplayIndex      = -1;
                bool dragEndPositionValid = IsMousePositionValidForColumnDrag(
                    2.0,
                    out newDisplayIndex);

                DataGridColumn column = _draggingSrcColumnHeader.Column;
                if (column != null && dragEndPositionValid && newDisplayIndex != column.DisplayIndex)
                {
                    column.DisplayIndex = newDisplayIndex;

                    DataGridColumnEventArgs columnEventArgs = new DataGridColumnEventArgs(_draggingSrcColumnHeader.Column);
                    ParentDataGrid.OnColumnReordered(columnEventArgs);
                }
            }

            _draggingSrcColumnHeader           = null;
            _columnHeaderDragIndicator         = null;
            _columnHeaderDropLocationIndicator = null;
        }
Пример #22
0
        private void dtgrid_sorting(object sender, DataGridColumnEventArgs e)
        {
            if (ActiveUser.User == "Administrator")
            {
                try
                {
                    if (e.Column.Tag.Equals("Event_Date"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.data_godzina_zdarzenia ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.data_godzina_zdarzenia descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }

                    else if (e.Column.Tag.Equals("user"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.user ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.user descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }

                    else if (e.Column.Tag.Equals("cam"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.kamera ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.kamera descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }

                    else if (e.Column.Tag.Equals("shift"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.zmiana ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.zmiana descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }

                    else if (e.Column.Tag.Equals("created"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.utworzone_data ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.utworzone_data descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }

                    else if (e.Column.Tag.Equals("type"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.rodzaj_zdarzenia ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.rodzaj_zdarzenia descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }

                    else if (e.Column.Tag.Equals("action"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.przekazanie ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.przekazanie descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }
                    else if (e.Column.Tag.Equals("loc"))
                    {
                        if (!(e.Column.SortDirection == DataGridSortDirection.Ascending))
                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.lokalizacja ascending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else

                        {
                            dtGrid.DataContext = new ObservableCollection <Zdarzenie>(from item in Db.ReadData_Zdarzenie()
                                                                                      orderby item.lokalizacja descending
                                                                                      select item);
                            e.Column.SortDirection = DataGridSortDirection.Descending;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ToastCreator.CreateToast(ex.Message, "Błąd");
                }
            }
        }
Пример #23
0
        private void dg_sorting(object sender, DataGridColumnEventArgs e)
        {
            if (e.Column.Tag.ToString() == null)
            {
                return;
            }
            // 直前に選ばれていたcollumが別ならアイコンを消しておく
            if (c != e.Column && c != null)
            {
                c.SortDirection = null;
            }

            if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Ascending)
            {
                // 選択collumが未選択・昇順状態であれば、降順にする
                e.Column.SortDirection = DataGridSortDirection.Descending;

                //選択Collumによって分岐
                if (e.Column.Tag.ToString() == "Date")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._date descending select i);
                }
                else if (e.Column.Tag.ToString() == "Type")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._type descending select i);
                }
                else if (e.Column.Tag.ToString() == "User")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._user_name descending select i);
                }
                else if (e.Column.Tag.ToString() == "Item")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._itemName descending select i);
                }
                else if (e.Column.Tag.ToString() == "Num")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._num descending select i);
                }
                else if (e.Column.Tag.ToString() == "Price")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._price descending select i);
                }
                else if (e.Column.Tag.ToString() == "Total")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._total_price descending select i);
                }
            }
            else
            {
                // 選択collumが降順状態であれば、昇順にする
                e.Column.SortDirection = DataGridSortDirection.Ascending;

                // 選択collumによって分岐
                if (e.Column.Tag.ToString() == "Date")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._date ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Type")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._type ascending select i);
                }
                else if (e.Column.Tag.ToString() == "User")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._user_name ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Item")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._itemName ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Num")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._num ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Price")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._price ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Total")
                {
                    dataGrid.ItemsSource = new ObservableCollection <PaymentLog>(from i in Logs orderby i._total_price ascending select i);
                }
            }
            // 現在選ばれていたcollumの保持
            c = e.Column;
        }
Пример #24
0
 private void dataGrid_ColumnLayoutChanged(object sender, DataGridColumnEventArgs e)
 {
     SaveColumnLayout();
 }
Пример #25
0
 /// <summary>
 ///     Called when the DisplayIndex of a column is modified.
 /// </summary>
 /// <remarks>
 ///     A column's DisplayIndex may be modified as the result of another column's DisplayIndex changing.  This is because the 
 ///     DataGrid enforces that the DisplayIndex of all Columns are unique integers from 0 to Columns.Count -1.
 /// </remarks>
 protected internal virtual void OnColumnDisplayIndexChanged(DataGridColumnEventArgs e)
 {
     if (ColumnDisplayIndexChanged != null)
     {
         ColumnDisplayIndexChanged(this, e);
     }
 }
Пример #26
0
        private void dg_SortSales(object sender, DataGridColumnEventArgs e)
        {
            if (e.Column.Tag.ToString() == "Sales Date")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortBySalesDateAsc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else //sort descending
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortBySalesDateDesc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }


            if (e.Column.Tag.ToString() == "Sales Amount")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortBySalesAmtAsc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else //sort descending
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortBySalesAmtDesc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }


            if (e.Column.Tag.ToString() == "Notes")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortBySalesNotesAsc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else //sort descending
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortBySalesNotesDesc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }
            if (e.Column.Tag.ToString() == "User")
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortByUserAsc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Ascending;
                }
                else //sort descending
                {
                    List <MBSales> myList = SalesSource.ToList <MBSales>();
                    myList.Sort(new MBSales.SortByUserDesc());

                    SalesSource.Clear();

                    foreach (MBSales item in myList)
                    {
                        SalesSource.Add(item);
                    }

                    e.Column.SortDirection = DataGridSortDirection.Descending;
                }
            }
        }
Пример #27
0
 protected override void OnColumnReordered(DataGridColumnEventArgs e)
 {
     UpdateColumnInfo();
     base.OnColumnReordered(e);
 }
 private void dataGrid_ColumnReordered(object sender, DataGridColumnEventArgs e)
 {
     currentCellPosition.SetCurrentCellIndex(CurrentRowCellEnumerationService, CurrentRowCellEnumerationService.GetCellIndex(currentCellElement));
     UpdateCurrentCell();
 }
Пример #29
0
        /// <summary>
        /// Called when data grid columns are reordered
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="DataGridColumnEventArgs"/> instance containing the event data.</param>
        private static void OnDataGridColumnReordered(object sender, DataGridColumnEventArgs e)
        {
            DataGrid dataGrid = (DataGrid)sender;

            UpdateColumnSettingsFromColumns(dataGrid);
        }
 private void dataGrid_ColumnDisplayIndexChanged(object sender, DataGridColumnEventArgs e)
 {
     cellService.SetCurrentCell(cellElementBeforeReordering);
     cellService.UpdateCurrentCell();
 }
Пример #31
0
        private void DataGrid_Sorting(object sender, DataGridColumnEventArgs e)
        {
            if (e.Column.Tag == null || ViewModel.IsLoading)
            {
                return;
            }

            var dataGrid = sender as DataGrid;

            if (dataGrid == null)
            {
                return;
            }

            if (string.Equals(e.Column.Tag.ToString(), "Name", StringComparison.OrdinalIgnoreCase))
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    ViewModel.SortNameAsc();

                    foreach (var column in dataGrid.Columns)
                    {
                        if (column == e.Column)
                        {
                            column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else
                        {
                            column.SortDirection = null;
                        }
                    }
                }
                else
                {
                    ViewModel.SortNameDesc();

                    foreach (var column in dataGrid.Columns)
                    {
                        if (column == e.Column)
                        {
                            column.SortDirection = DataGridSortDirection.Descending;
                        }
                        else
                        {
                            column.SortDirection = null;
                        }
                    }
                }
            }
            else if (string.Equals(e.Column.Tag.ToString(), "Size", StringComparison.OrdinalIgnoreCase))
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    ViewModel.SortSizeAsc();

                    foreach (var column in dataGrid.Columns)
                    {
                        if (column == e.Column)
                        {
                            column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else
                        {
                            column.SortDirection = null;
                        }
                    }
                }
                else
                {
                    ViewModel.SortSizeDesc();

                    foreach (var column in dataGrid.Columns)
                    {
                        if (column == e.Column)
                        {
                            column.SortDirection = DataGridSortDirection.Descending;
                        }
                        else
                        {
                            column.SortDirection = null;
                        }
                    }
                }
            }
            else if (string.Equals(e.Column.Tag.ToString(), "Date", StringComparison.OrdinalIgnoreCase))
            {
                if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Descending)
                {
                    ViewModel.SortDateAsc();

                    foreach (var column in dataGrid.Columns)
                    {
                        if (column == e.Column)
                        {
                            column.SortDirection = DataGridSortDirection.Ascending;
                        }
                        else
                        {
                            column.SortDirection = null;
                        }
                    }
                }
                else
                {
                    ViewModel.SortDateDesc();

                    foreach (var column in dataGrid.Columns)
                    {
                        if (column == e.Column)
                        {
                            column.SortDirection = DataGridSortDirection.Descending;
                        }
                        else
                        {
                            column.SortDirection = null;
                        }
                    }
                }
            }
        }
Пример #32
0
        //private void List_AddingNew(object sender, AddingNewEventArgs e)
        //{

        //    //数据绑定
        //    var model = (WorkLogsModel) e.NewObject;
        //    model.DateTime = DateTime.Today;
        //    model.Name = dname;
        //    model.Whours = 8;
        //}

        //private void List_ListChanged(object sender, ListChangedEventArgs e)
        //{


        //}

        private void dgvList_ColumnDisplayIndexChanged(object sender, DataGridColumnEventArgs e)
        {
            //保存列序
            SaveColumnOrder((DataGrid)sender);
        }
Пример #33
0
        internal void OnColumnDisplayIndexChanged(DataGridColumnBase dataGridColumn)
        { 
            Debug.Assert(dataGridColumn != null);
            DataGridColumnEventArgs e = new DataGridColumnEventArgs(dataGridColumn);
 
            // Call protected method to raise event
            OnColumnDisplayIndexChanged(e);
        } 
        private void ProcessSort()
        {
            if (this.OwningColumn != null &&
                this.OwningGrid != null &&
                this.OwningGrid.EditingRow == null &&
                this.OwningColumn != this.OwningGrid.ColumnsInternal.FillerColumn &&
                this.OwningGrid.CanUserSortColumns &&
                this.OwningColumn.CanUserSort)
            {
                DataGridColumnEventArgs ea = new DataGridColumnEventArgs(this.OwningColumn);
                this.OwningGrid.OnColumnSorting(ea);

#if FEATURE_ICOLLECTIONVIEW_SORT
                if (!ea.Handled && this.OwningGrid.DataConnection.AllowSort && this.OwningGrid.DataConnection.SortDescriptions != null)
                {
                    // - DataConnection.AllowSort is true, and
                    // - SortDescriptionsCollection exists, and
                    // - the column's data type is comparable
                    DataGrid          owningGrid = this.OwningGrid;
                    ListSortDirection newSortDirection;
                    SortDescription   newSort;

                    bool ctrl;
                    bool shift;

                    KeyboardHelper.GetMetaKeyState(out ctrl, out shift);

                    SortDescription?sort           = this.OwningColumn.GetSortDescription();
                    ICollectionView collectionView = owningGrid.DataConnection.CollectionView;
                    Debug.Assert(collectionView != null);
                    try
                    {
                        owningGrid.OnUserSorting();
                        using (collectionView.DeferRefresh())
                        {
                            // If shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                            if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                            {
                                if (collectionView.CanGroup && collectionView.GroupDescriptions != null)
                                {
                                    // Make sure we sort by the GroupDescriptions first
                                    for (int i = 0; i < collectionView.GroupDescriptions.Count; i++)
                                    {
                                        PropertyGroupDescription groupDescription = collectionView.GroupDescriptions[i] as PropertyGroupDescription;
                                        if (groupDescription != null && collectionView.SortDescriptions.Count <= i || collectionView.SortDescriptions[i].PropertyName != groupDescription.PropertyName)
                                        {
                                            collectionView.SortDescriptions.Insert(Math.Min(i, collectionView.SortDescriptions.Count), new SortDescription(groupDescription.PropertyName, ListSortDirection.Ascending));
                                        }
                                    }
                                    while (collectionView.SortDescriptions.Count > collectionView.GroupDescriptions.Count)
                                    {
                                        collectionView.SortDescriptions.RemoveAt(collectionView.GroupDescriptions.Count);
                                    }
                                }
                                else if (!shift)
                                {
                                    owningGrid.DataConnection.SortDescriptions.Clear();
                                }
                            }

                            if (sort.HasValue)
                            {
                                // swap direction
                                switch (sort.Value.Direction)
                                {
                                case ListSortDirection.Ascending:
                                    newSortDirection = ListSortDirection.Descending;
                                    break;

                                default:
                                    newSortDirection = ListSortDirection.Ascending;
                                    break;
                                }

                                newSort = new SortDescription(sort.Value.PropertyName, newSortDirection);

                                // changing direction should not affect sort order, so we replace this column's
                                // sort description instead of just adding it to the end of the collection
                                int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort.Value);
                                if (oldIndex >= 0)
                                {
                                    owningGrid.DataConnection.SortDescriptions.Remove(sort.Value);
                                    owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                                }
                                else
                                {
                                    owningGrid.DataConnection.SortDescriptions.Add(newSort);
                                }
                            }
                            else
                            {
                                // start new sort
                                newSortDirection = ListSortDirection.Ascending;

                                string propertyName = this.OwningColumn.GetSortPropertyName();

                                // no-opt if we couldn't find a property to sort on
                                if (string.IsNullOrEmpty(propertyName))
                                {
                                    return;
                                }

                                newSort = new SortDescription(propertyName, newSortDirection);

                                owningGrid.DataConnection.SortDescriptions.Add(newSort);
                            }
                        }
                    }
                    finally
                    {
                        owningGrid.OnUserSorted();
                    }

                    sortProcessed = true;
                }
#endif

                // Send the Invoked event for the column header's automation peer.
                DataGridAutomationPeer.RaiseAutomationInvokeEvent(this);
            }
        }
        private void dg_sorting(object sender, DataGridColumnEventArgs e)
        {
            if (e.Column.Tag.ToString() == null)
            {
                return;
            }
            // 直前に選ばれていたcollumが別ならアイコンを消しておく
            if (c != e.Column && c != null)
            {
                c.SortDirection = null;
            }

            if (e.Column.SortDirection == null || e.Column.SortDirection == DataGridSortDirection.Ascending)
            {
                // 選択collumが未選択・昇順状態であれば、降順にする
                e.Column.SortDirection = DataGridSortDirection.Descending;

                //選択Collumによって分岐
                if (e.Column.Tag.ToString() == "mid")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._mid descending select i);
                }
                else if (e.Column.Tag.ToString() == "User")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._user_name descending select i);
                }
                else if (e.Column.Tag.ToString() == "Balance")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._balance descending select i);
                }
                else if (e.Column.Tag.ToString() == "Permission")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._permission descending select i);
                }
            }
            else
            {
                // 選択collumが降順状態であれば、昇順にする
                e.Column.SortDirection = DataGridSortDirection.Ascending;

                //選択Collumによって分岐
                if (e.Column.Tag.ToString() == "mid")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._mid ascending select i);
                }
                else if (e.Column.Tag.ToString() == "User")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._user_name ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Balance")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._balance ascending select i);
                }
                else if (e.Column.Tag.ToString() == "Permission")
                {
                    dataGrid.ItemsSource = new ObservableCollection <UsersInformation>(from i in Users orderby i._permission ascending select i);
                }
            }
            // 現在選ばれていたcollumの保持
            c = e.Column;
        }
        internal void OnMouseLeftButtonUp(ref bool handled, Point mousePosition, Point mousePositionHeaders)
        {
            this.IsPressed = false;

            if (this.OwningGrid != null && this.OwningGrid.ColumnHeaders != null)
            {
                if (_dragMode == DragMode.MouseDown)
                {
                   OnMouseLeftButtonUp_Click(ref handled);
                }
                else if (_dragMode == DragMode.Reorder)
                {
                    // Find header we're hovering over
                    int targetIndex = this.GetReorderingTargetDisplayIndex(mousePositionHeaders);

                    if (((!this.OwningColumn.IsFrozen && targetIndex >= this.OwningGrid.FrozenColumnCount)
                          || (this.OwningColumn.IsFrozen && targetIndex < this.OwningGrid.FrozenColumnCount)))
                    {
                        this.OwningColumn.DisplayIndex = targetIndex;

                        DataGridColumnEventArgs ea = new DataGridColumnEventArgs(this.OwningColumn);
                        this.OwningGrid.OnColumnReordered(ea);
                    }

                    DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(mousePosition.X - _dragStart.Value.X, mousePosition.Y - _dragStart.Value.Y, false);
                    this.OwningGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
                }
                else if (_dragMode == DragMode.Drag)
                {
                    DragCompletedEventArgs dragCompletedEventArgs = new DragCompletedEventArgs(0, 0, false);
                    this.OwningGrid.OnColumnHeaderDragCompleted(dragCompletedEventArgs);
                }

                SetDragCursor(mousePosition);

                // Variables that track drag mode states get reset in DataGridColumnHeader_LostMouseCapture
                ReleaseMouseCapture();
                DataGridColumnHeader._dragMode = DragMode.None;
                handled = true;
            }
        }