Exemplo n.º 1
0
        private void OnSortDescending(object parameter)
        {
            GridViewHeaderCell cell = parameter as GridViewHeaderCell;

            if (cell != null && cell.Column != null && cell.Column.CanSort() && cell.Column.DataControl != null && cell.Column.SortingState != SortingState.Descending)
            {
                Sort(cell, ListSortDirection.Descending);
            }
        }
Exemplo n.º 2
0
        void OnMenuOpened(object sender, RoutedEventArgs e)
        {
            RadContextMenu     menu = (RadContextMenu)sender;
            GridViewHeaderCell cell = menu.GetClickedElement <GridViewHeaderCell>();

            if (cell != null)
            {
                menu.Items.Clear();

                RadMenuItem item = new RadMenuItem();
                item.Header = String.Format(@"Sort Ascending by ""{0}""", cell.Column.Header);
                menu.Items.Add(item);

                item        = new RadMenuItem();
                item.Header = String.Format(@"Sort Descending by ""{0}""", cell.Column.Header);
                menu.Items.Add(item);

                item        = new RadMenuItem();
                item.Header = String.Format(@"Clear Sorting by ""{0}""", cell.Column.Header);
                menu.Items.Add(item);

                item        = new RadMenuItem();
                item.Header = String.Format(@"Group by ""{0}""", cell.Column.Header);
                menu.Items.Add(item);

                item        = new RadMenuItem();
                item.Header = String.Format(@"Ungroup ""{0}""", cell.Column.Header);
                menu.Items.Add(item);

                item        = new RadMenuItem();
                item.Header = "Choose Columns:";
                menu.Items.Add(item);

                // create menu items
                foreach (GridViewColumn column in grid.Columns)
                {
                    RadMenuItem subMenu = new RadMenuItem();
                    subMenu.Header      = column.Header;
                    subMenu.IsCheckable = true;
                    subMenu.IsChecked   = true;

                    Binding isCheckedBinding = new Binding("IsVisible");
                    isCheckedBinding.Mode   = BindingMode.TwoWay;
                    isCheckedBinding.Source = column;

                    // bind IsChecked menu item property to IsVisible column property
                    subMenu.SetBinding(RadMenuItem.IsCheckedProperty, isCheckedBinding);

                    item.Items.Add(subMenu);
                }
            }
            else
            {
                menu.IsOpen = false;
            }
        }
Exemplo n.º 3
0
        void OnMenuItemClick(object sender, RoutedEventArgs e)
        {
            RadContextMenu menu = (RadContextMenu)sender;

            GridViewHeaderCell cell        = menu.GetClickedElement <GridViewHeaderCell>();
            RadMenuItem        clickedItem = ((RadRoutedEventArgs)e).OriginalSource as RadMenuItem;
            GridViewColumn     column      = cell.Column;

            if (clickedItem.Parent is RadMenuItem)
            {
                return;
            }

            string header = Convert.ToString(clickedItem.Tag);

            using (grid.DeferRefresh())
            {
                ColumnSortDescriptor sd = (from d in grid.SortDescriptors.OfType <ColumnSortDescriptor>()
                                           where d.Column == column
                                           select d).FirstOrDefault();

                if (header.Contains("Ascending"))
                {
                    if (sd != null)
                    {
                        grid.SortDescriptors.Remove(sd);
                    }

                    ColumnSortDescriptor newDescriptor = new ColumnSortDescriptor();
                    newDescriptor.Column        = column;
                    newDescriptor.SortDirection = ListSortDirection.Ascending;

                    grid.SortDescriptors.Add(newDescriptor);
                }
                else if (header.Contains("Descending"))
                {
                    if (sd != null)
                    {
                        grid.SortDescriptors.Remove(sd);
                    }

                    ColumnSortDescriptor newDescriptor = new ColumnSortDescriptor();
                    newDescriptor.Column        = column;
                    newDescriptor.SortDirection = ListSortDirection.Descending;

                    grid.SortDescriptors.Add(newDescriptor);
                }
                else if (header.Contains("Clear"))
                {
                    if (sd != null)
                    {
                        grid.SortDescriptors.Remove(sd);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private bool CanSortDescending(object parameter)
        {
            GridViewHeaderCell cell = parameter as GridViewHeaderCell;

            if (cell != null && cell.Column != null && cell.Column.CanSort() && cell.Column.DataControl != null && cell.Column.SortingState != SortingState.Descending)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        private void OnClearSort(object parameter)
        {
            GridViewHeaderCell cell = parameter as GridViewHeaderCell;

            if (cell != null && cell.Column != null && cell.Column.CanSort() && cell.Column.DataControl != null && cell.Column.SortingState != SortingState.None)
            {
                RadGridView          grid = cell.Column.DataControl as RadGridView;
                ColumnSortDescriptor sd   = (from d in grid.SortDescriptors.OfType <ColumnSortDescriptor>()
                                             where object.Equals(d.Column, cell.Column)
                                             select d).FirstOrDefault();

                if (sd != null)
                {
                    grid.SortDescriptors.Remove(sd);
                }
            }
        }
Exemplo n.º 6
0
        private static void Sort(GridViewHeaderCell cell, ListSortDirection sortDirection)
        {
            RadGridView grid = cell.Column.DataControl as RadGridView;
            ColumnSortDescriptor sd = (from d in grid.SortDescriptors.OfType<ColumnSortDescriptor>()
                                       where object.Equals(d.Column, cell.Column)
                                       select d).FirstOrDefault();

            if (sd != null)
            {
                grid.SortDescriptors.Remove(sd);
            }

            ColumnSortDescriptor newDescriptor = new ColumnSortDescriptor();
            newDescriptor.Column = cell.Column;
            newDescriptor.SortDirection = sortDirection;

            grid.SortDescriptors.Add(newDescriptor);
        }
Exemplo n.º 7
0
        private void OnUngroup(object parameter)
        {
            GridViewHeaderCell cell = parameter as GridViewHeaderCell;

            if (cell != null && cell.Column != null && cell.Column.DataControl != null && cell.Column.CanGroup())
            {
                RadGridView grid = cell.Column.DataControl as RadGridView;

                ColumnGroupDescriptor gd = (from d in grid.GroupDescriptors.OfType <ColumnGroupDescriptor>()
                                            where object.Equals(d.Column, cell.Column)
                                            select d).FirstOrDefault();

                if (gd != null)
                {
                    grid.GroupDescriptors.Remove(gd);
                }
            }
        }
Exemplo n.º 8
0
        private static void Sort(GridViewHeaderCell cell, ListSortDirection sortDirection)
        {
            RadGridView          grid = cell.Column.DataControl as RadGridView;
            ColumnSortDescriptor sd   = (from d in grid.SortDescriptors.OfType <ColumnSortDescriptor>()
                                         where object.Equals(d.Column, cell.Column)
                                         select d).FirstOrDefault();

            if (sd != null)
            {
                grid.SortDescriptors.Remove(sd);
            }

            ColumnSortDescriptor newDescriptor = new ColumnSortDescriptor();

            newDescriptor.Column        = cell.Column;
            newDescriptor.SortDirection = sortDirection;

            grid.SortDescriptors.Add(newDescriptor);
        }
Exemplo n.º 9
0
        /// <summary>
        /// The OnMenuItemClick.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="RoutedEventArgs"/>.</param>
        public void OnMenuItemClick(object sender, RoutedEventArgs e)
        {
            RadContextMenu menu = (RadContextMenu)sender;

            GridViewHeaderCell cell   = menu.GetClickedElement <GridViewHeaderCell>();
            GridViewColumn     column = cell.Column;

            string header = string.Empty;

            if (((RadRoutedEventArgs)e).OriginalSource is RadMenuItem clickedItem)
            {
                if (clickedItem?.Parent is RadMenuItem)
                {
                    return;
                }
                else
                {
                    header = (string)clickedItem !.Header ?? string.Empty;
                }
            }

            using (_grid.DeferRefresh())
            {
                ColumnSortDescriptor sd = (from d in _grid.SortDescriptors.OfType <ColumnSortDescriptor>()
                                           where object.Equals(d.Column, column)
                                           select d).FirstOrDefault();

                if (header !.Contains("Sort Ascending"))
                {
                    if (sd != null)
                    {
                        _grid.SortDescriptors.Remove(sd);
                    }

                    ColumnSortDescriptor newDescriptor = new ColumnSortDescriptor
                    {
                        Column        = column,
                        SortDirection = ListSortDirection.Ascending,
                    };

                    _grid.SortDescriptors.Add(newDescriptor);
                }
Exemplo n.º 10
0
        private bool CanGroupby(object parameter)
        {
            GridViewHeaderCell cell = parameter as GridViewHeaderCell;

            if (cell != null && cell.Column != null && cell.Column.DataControl != null && cell.Column.CanGroup())
            {
                RadGridView grid = cell.Column.DataControl as RadGridView;

                ColumnGroupDescriptor gd = (from d in grid.GroupDescriptors.OfType <ColumnGroupDescriptor>()
                                            where object.Equals(d.Column, cell.Column)
                                            select d).FirstOrDefault();

                if (gd == null)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 11
0
        private void OnGroupby(object parameter)
        {
            GridViewHeaderCell cell = parameter as GridViewHeaderCell;

            if (cell != null && cell.Column != null && cell.Column.DataControl != null && cell.Column.CanGroup())
            {
                RadGridView grid = cell.Column.DataControl as RadGridView;

                ColumnGroupDescriptor gd = (from d in grid.GroupDescriptors.OfType <ColumnGroupDescriptor>()
                                            where object.Equals(d.Column, cell.Column)
                                            select d).FirstOrDefault();

                if (gd == null)
                {
                    ColumnGroupDescriptor newDescriptor = new ColumnGroupDescriptor();
                    newDescriptor.Column        = cell.Column;
                    newDescriptor.SortDirection = ListSortDirection.Ascending;
                    grid.GroupDescriptors.Add(newDescriptor);
                }
            }
        }
        /// <summary>
        /// catch click on header cells
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void MouseDownOnHeaderCell(object sender, MouseEventArgs args)
        {
            if (dgRelativePerformance.Items.Count != 0)
            {
                GridViewHeaderCell cellClicked = ((FrameworkElement)args.OriginalSource).ParentOfType <GridViewHeaderCell>();
                if (cellClicked == null)
                {
                    GridViewFooterCell footerTotalClicked = ((FrameworkElement)args.OriginalSource).ParentOfType <GridViewFooterCell>();
                    if (footerTotalClicked == null)
                    {
                        return;
                    }

                    if ((args.OriginalSource as TextBlock).Text == "Total")
                    {
                        eventAggregator.GetEvent <RelativePerformanceGridClickEvent>().Publish(new RelativePerformanceGridCellData()
                        {
                            CountryID = null,
                            SectorID  = null,
                        });
                        this.dgRelativePerformance.SelectedItems.Clear();
                    }
                }
                else
                {
                    if (cellClicked.Column.UniqueName == "Total")
                    {
                        eventAggregator.GetEvent <RelativePerformanceGridClickEvent>().Publish(new RelativePerformanceGridCellData()
                        {
                            CountryID = null,
                            SectorID  = null,
                        });
                        this.dgRelativePerformance.SelectedItems.Clear();
                    }
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// The OnMenuOpened.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="RoutedEventArgs"/>.</param>
        public void OnMenuOpened(object sender, RoutedEventArgs e)
        {
            RadContextMenu     menu = (RadContextMenu)sender;
            GridViewHeaderCell cell = menu.GetClickedElement <GridViewHeaderCell>();

            if (cell != null)
            {
                menu.Items.Clear();

                if (cell.Column.CanFilter())
                {
                    string insertString = (string)(cell.Column.Tag ?? cell.Column.Header);
                    menu.Items.Add(new RadMenuItem
                    {
                        Header = string.Format(@"Sort Ascending by ""{0}""", insertString),
                    });

                    menu.Items.Add(new RadMenuItem
                    {
                        Header = string.Format(@"Sort Descending by ""{0}""", insertString),
                    });

                    menu.Items.Add(new RadMenuItem
                    {
                        Header = string.Format(@"Clear Sorting by ""{0}""", insertString),
                    });

                    menu.Items.Add(new RadMenuItem
                    {
                        Header = string.Format(@"Group by ""{0}""", insertString),
                    });

                    menu.Items.Add(new RadMenuItem
                    {
                        Header = string.Format(@"Ungroup ""{0}""", insertString),
                    });
                }

                RadMenuItem item = new RadMenuItem
                {
                    Header = "Choose Columns:",
                };
                menu.Items.Add(item);

                // create menu items
                foreach (GridViewColumn column in _grid.Columns)
                {
                    RadMenuItem subMenu = new RadMenuItem
                    {
                        Header      = column.Tag ?? column.Header,
                        IsCheckable = true,
                        IsChecked   = true,
                    };

                    Binding isCheckedBinding = new Binding("IsVisible")
                    {
                        Mode   = BindingMode.TwoWay,
                        Source = column,
                    };

                    // bind IsChecked menu item property to IsVisible column property
                    subMenu.SetBinding(RadMenuItem.IsCheckedProperty, isCheckedBinding);
                    item.Items.Add(subMenu);
                }
            }
            else
            {
                menu.IsOpen = false;
            }
        }