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); } } } }
/// <summary> /// Raises the <see cref="E:SelectedGroupDescriptionChanged"/> event. /// </summary> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> protected virtual void OnSelectedGroupDescriptionChanged(DependencyPropertyChangedEventArgs e) { if (RadGridView != null) { using (RadGridView.DeferRefresh()) { UpdateGrouping(e.NewValue as GroupDescription); } } else { UpdateGrouping(e.NewValue as GroupDescription); } }
/// <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); }
void OnMenuItemClick(object sender, RoutedEventArgs e) { var menu = (RadContextMenu)sender; var cell = menu.GetClickedElement <GridViewCell>(); var clickedItem = ((RadRoutedEventArgs)e).OriginalSource as RadMenuItem; string header = Convert.ToString(clickedItem.Header); using (grid.DeferRefresh()) { switch (header) { case "Copy All": this.grid.ClipboardCopyMode = GridViewClipboardCopyMode.All; break; case "Copy with headers": this.grid.ClipboardCopyMode = GridViewClipboardCopyMode.Header | GridViewClipboardCopyMode.Cells; break; case "Copy with footers": this.grid.ClipboardCopyMode = GridViewClipboardCopyMode.Footer | GridViewClipboardCopyMode.Cells; break; case "Default": this.grid.ClipboardCopyMode = GridViewClipboardCopyMode.Default; break; case "Disable copying": this.grid.ClipboardCopyMode = GridViewClipboardCopyMode.None; break; case "Default Pasting": this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.Default; break; case "Skip hidden columns": this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.SkipHiddenColumns; break; case "Skip first and last line": this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.SkipFirstLine | GridViewClipboardPasteMode.SkipLastLine; break; case "Override all selected cells on pasting": this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.AllSelectedCells; break; case "Override all selected items on pasting": //this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.AllSelectedRows; break; case "Insert new items on pasting": // this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.InsertNewRows; break; case "Disable Pasting": this.grid.ClipboardPasteMode = GridViewClipboardPasteMode.None; break; } } }
public void LoadStateCore() { if (this.grid != null) { grid.FrozenColumnCount = Settings.FrozenColumnCount; if (Settings.ColumnSettings.Count > 0) { foreach (ColumnSetting setting in Settings.ColumnSettings) { ColumnSetting currentSetting = setting; GridViewDataColumn column = (from c in grid.Columns.OfType <GridViewDataColumn>() where c.UniqueName == currentSetting.UniqueName select c).FirstOrDefault(); if (column != null) { if (currentSetting.DisplayIndex != null && currentSetting.DisplayIndex.Value < grid.Columns.Count) { column.DisplayIndex = currentSetting.DisplayIndex.Value; } if (setting.Width != null) { column.Width = new GridViewLength(setting.Width.Value); } } } } using (grid.DeferRefresh()) { if (Settings.SortSettings.Count > 0) { grid.SortDescriptors.Clear(); foreach (SortSetting setting in Settings.SortSettings) { Telerik.Windows.Data.SortDescriptor d = new Telerik.Windows.Data.SortDescriptor(); d.Member = setting.PropertyName; d.SortDirection = setting.SortDirection; grid.SortDescriptors.Add(d); } } if (Settings.GroupSettings.Count > 0) { grid.GroupDescriptors.Clear(); foreach (GroupSetting setting in Settings.GroupSettings) { Telerik.Windows.Data.GroupDescriptor d = new Telerik.Windows.Data.GroupDescriptor(); d.Member = setting.PropertyName; d.SortDirection = setting.SortDirection; d.DisplayContent = setting.DisplayContent; grid.GroupDescriptors.Add(d); } } if (Settings.FilterSettings.Count > 0) { foreach (FilterSetting setting in Settings.FilterSettings) { FilterSetting currentSetting = setting; GridViewDataColumn matchingColumn = (from column in grid.Columns.OfType <GridViewDataColumn>() where column.DataMemberBinding.Path.Path == currentSetting.PropertyName select column).FirstOrDefault(); //if (matchingColumn != null) { // ColumnFilterDescriptor cfd = new ColumnFilterDescriptor(matchingColumn); // if (setting.Filter1 != null) { // cfd.FieldFilter.Filter1.Member = setting.Filter1.Member; // cfd.FieldFilter.Filter1.Operator = setting.Filter1.Operator; // cfd.FieldFilter.Filter1.Value = setting.Filter1.Value; // } // if (setting.Filter2 != null) { // cfd.FieldFilter.Filter2.Member = setting.Filter2.Member; // cfd.FieldFilter.Filter2.Operator = setting.Filter2.Operator; // cfd.FieldFilter.Filter2.Value = setting.Filter2.Value; // } // foreach (Telerik.Windows.Data.FilterDescriptor descriptor in setting.SelectedDistinctValues) { // cfd.DistinctFilter.FilterDescriptors.Add(descriptor); // } // this.grid.FilterDescriptors.Add(cfd); //} } } } } }