This is a migrated thread and some comments may be shown as answers.

Update cell control style on paste

3 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dolly
Top achievements
Rank 1
Dolly asked on 12 Jan 2018, 08:19 AM

I am unable to update the cell background color on the paste of cell values.

I have tried the Pasted, Pasting, PastingCellClipboardContent events on the radgridview. All of this events provide GridViewCellInfo which does not contain the enough information to update background color of the cell.

Also CellValidating event is not fired for the pasted cells in the radgridview, could you please let me know the reason for the same?

 

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 16 Jan 2018, 04:38 PM
Hello Dolly,

In order to change the background of the cell during a paste operation you can just use the CurrentCell property of the RadGridView. You can do that in the Pasting or Pasted events. That approach would look something like this:
private void radGridView_Pasting(object sender, GridViewClipboardEventArgs e)
{
    var grid = sender as RadGridView;
    grid.CurrentCell.Background = Brushes.Yellow;
}

As for the CellValidating event, it is intended to be fired when the RadGridView cells are edited manually. 

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Dolly
Top achievements
Rank 1
answered on 22 Jan 2018, 06:19 AM

Thanks for the Update Vladimir!

I have tried Pasting and Pasted event but both did not helped me.

In case of my scenario,  I am pasting more than one cells at the same time. Pasting or Pasted event is fired only once and in the currentcell gives first cell from which pasting started. This is not helping to update the background of all the cells which are pasted.

 

0
Vladimir Stoyanov
Telerik team
answered on 23 Jan 2018, 05:45 PM
Hello Dolly,

Thank you for the additional information.

In that case what I can suggest is to use a CellStyleSelector and extract the GridViewCell ControlTemplate and create a modified style in order to apply it to the necessary cells on paste. Please note that this is required because working directly with the visual elements is not recommended. This has been explained in more detail in the UI Virtualization article.

As for the concrete implementation, you can create a dictionary in the model of the RadGridView rows which will hold the information for whether a certain cell has been pasted in. Its key can indicate the property which has been modified or not. You can set the values of dictionary in the PastingCellClipboardContent event and check them in the SelectStyle method of the style selector to conditionally return you custom style for pasted cells.

I am attaching a sample project demonstrating this approach for your reference. Of course, you would need to adapt this example to your particular scenario.

I hope that you find this helpful.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Dolly
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Dolly
Top achievements
Rank 1
Share this question
or