void OnCopied(object sender, Telerik.Windows.RadRoutedEventArgs e) { var productIDColumn = this.grid.Columns["ProductID"]; this.dataContext = grid.DataContext as MyViewModel; if (this.dataContext != null && !this.dataContext.ShouldCopySelectColumn && this.grid.ClipboardCopyMode.HasFlag(GridViewClipboardCopyMode.Header)) { string originalText = Telerik.Windows.Controls.Clipboard.GetText(); string updatedText = string.Empty; if (this.grid.SelectionMode == System.Windows.Controls.SelectionMode.Single) { updatedText = originalText.Remove(0, 1); } else { var originalColumnHeader = originalText.Split('\t').FirstOrDefault(t => t.Contains("CheckBox")); updatedText = originalText.Remove(0, originalColumnHeader.Length + 1); } Telerik.Windows.Controls.Clipboard.SetText(updatedText); } if (productIDColumn.IsVisible && this.grid.ClipboardCopyMode.HasFlag(GridViewClipboardCopyMode.Header)) { var headerText = (productIDColumn.Header as TextBlock).Text; string originalText = Telerik.Windows.Controls.Clipboard.GetText(); var originalColumnHeader = originalText.Split('\t').FirstOrDefault(t => t.Contains("TextBlock")); var updatedText = originalText.Replace(originalColumnHeader, headerText); Telerik.Windows.Controls.Clipboard.SetText(updatedText); } }
void OnCopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e) { this.dataContext = grid.DataContext as MyViewModel; if (this.dataContext != null) { if (!this.dataContext.ShouldCopySelectColumn && !(e.Cell.Column is GridViewDataColumn) && !(e.Cell.Column is GridViewExpressionColumn)) { e.Cancel = true; } } }
public GridViewClipboardCustomBehavior(RadGridView grid) { this.grid = grid; this.dataContext = grid.DataContext as MyViewModel; }