Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
XamGrid: change style for pasted cells
posted

Hi everyone 

I just found how to do that for copied cells, How to do it for pasted cells? 

Parents Reply
  • 29105
    Suggested Answer
    Offline posted in reply to Vasily Kramor

    The following code will provide you with the ability to modify pasted cells. The two styles are listed in XAML. Please see my attached sample for more details. 0410.WpfApplication1.zip

    public partial class MainWindow : Window
        {
            private List<CellBase> previouslySelectedCells = null;
            List<CellBase> selectedCells = null;
            bool IsValidSelectedRec; 
    
            ComponentData data = new ComponentData();
            public MainWindow()
            {
                InitializeComponent();
                this.DataContext = data.GenerateData(50);
            }
    
            private void xGrid_ClipboardPasting(object sender, Infragistics.Controls.Grids.ClipboardPastingEventArgs e)
            {
                if (IsValidSelectedRec)
                {
                    // Color in blue the valid cell selection
                    System.Windows.Style CellStyleResource = this.Resources["CopiedCellStyle"] as System.Windows.Style;
                    this.SetCellStyle(selectedCells, CellStyleResource);
                }
                else
                {
                    // Color in red the invalid cell selection
                    System.Windows.Style CellStyleResource = this.Resources["InvalidSelectionCellStyle"] as System.Windows.Style;
                    this.SetCellStyle(selectedCells, CellStyleResource);
                    
                }
                
            }
    
            private void xGrid_ClipboardCopying(object sender, Infragistics.Controls.Grids.ClipboardCopyingEventArgs e)
            {
                // Get selected cells
                List<CellBase> selectedCells = new List<CellBase>(e.SelectedItems);
                previouslySelectedCells = selectedCells;
                // Clear the style of the previously selected cells
                if (previouslySelectedCells != null && previouslySelectedCells.Count > 0)
                {
                    this.SetCellStyle(previouslySelectedCells, null);
                }
    
                // Check if the selected region of cells is valid for pasting
                IsValidSelectedRec = e.ValidateSelectedRectangle();
    
            }
    
            private void SetCellStyle(List<CellBase> cells, System.Windows.Style cellsStyle)
            {
                
                foreach (CellBase cell in previouslySelectedCells)
                {
                    if (cell is Cell)
                    {
                        cell.Style = cellsStyle;
                    }
                    // Set a new style to the copied cells
                   
                }
            }
        }

    Let me know if you have any questions.

    Sincerely,

    Michael Di Filippo
    Associate Software Developer
    Infragistics, Inc.
    www.infragistics.com/support

Children