Hi everyone
I just found how to do that for copied cells, How to do it for pasted cells?
Hello Vasily,
I recommend using the ClipboardPasting event and modify the cell in the same manner you used to copy the cells. For more details about the pasted event please refer to our online documentation here:
https://es.infragistics.com/help/wpf/xamgrid-paste-event-and-event-arguments
Let me know if you have any questions.
I am not sure how it should help me. In the copy methods i has an object which represents a cell and i can chsnge the style for it. How can i get a cell in which will be pasted data next?
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 } } }
Sincerely,
Michael Di FilippoAssociate Software DeveloperInfragistics, Inc.www.infragistics.com/support
Thanks for the project, but....
DId you run this application? This app is confused me, why cell styles changes for the previously selected cells?
I would expect to paste copied data to another place of the grid. What should I do if I will paste data from the Excel?
The sample demonstrated how to style the pasted cells. Unfortunately the ClipboardPasting event doesn't expose a selected cells collection as an event argument to properly achieve your requirement with ease. Therefore you are going to have to manually keep track of the pasted cells by first inspecting the ActiveCell in the ClipboardPasting event and iterating through the rows to find the rest of the pasted cells.
This is considered to be a new product idea. You can suggest new product ideas for future versions by emailing ideas@infragistics.com.
Submitting your idea will send it directly to our product management team so that it can be imported into our new ideas community once live: http://ideas.infragistics.com.
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. You can also link back to this thread for additional details.
I will spend some more time researching this and I'll follow up tomorrow. Thank you for your patience.
Thaks for help, but I made my custom copy and paste functionality.
Hello,
I attached a new sample to help you get started with modifying the pasted cells. I added a method that styles each cell from the SelectedCells collection from the SelectionSettings object of the XamGrid and removed any styling that was occurring in the copy event.
Please review my sample and let me know if you have any questions. WpfApplication1 (modifyPastedCells).zip