We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

2 questions on SfDataGrid

Hi,

I'm trying to accomplish a copy - paste and color changing in an SfDataGrid.
 
1. Copy - Paste between 2 SfDataGrids

I have 2 SfDataGrids, A and B.

I want to select a row from A and by pressing a button to copy the  row and paste it at B.

I'm not sure if I'm missing something with the Copy / Paste functions.

Data selectedRow = ( Data )A.SelectedItem;

if( selectedRow != null )
{
     A.GridCopyPaste.Copy();

     B.GridCopyPaste.Paste();
 
     B.View.Refresh();
}



2. I need to change row background and foreground colors upon selecting a row and then pressing of a button.

 

How can I accomplish that?

Regards.

Dov.

            

1 Reply

MK Muthukumar Kalyanasundaram Syncfusion Team April 4, 2017 04:24 PM UTC

Hi Dov, 

Thank you for contacting Syncfusion support. 

We have analyzed your query. 

Query 1:  “Copy & paste the selected item between two SfDataGrid ”. 

If you want to copy and paste the selected item between two datagrid, you can achieve your requirement by setting GridCopyPaste.Copy() and GridCopyPPaste.Paste() method. When we copy and paste the selected item in another grid, you need to specific index to be paste the record. Could you please refer the below code snippet and sample in below location, 
 
Code Snippet:  

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    var currentCell = gridA.SelectionController.CurrentCellManager.CurrentCell; 
    var record = this.gridA.GetRecordAtRowIndex(currentCell.RowIndex); 
    this.gridA.SelectedItem = record;             
    gridA.GridCopyPaste.Copy(); 
    // need to specific the index to paste the record in grid 
    this.gridB.SelectionController.MoveCurrentCell(new Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex(currentCell.RowIndex,currentCell.ColumnIndex),true); 
    gridB.GridCopyPaste.Paste(); 
} 


Query 2:  To change row background and foreground colors upon selecting a row and then pressing of a button 
 
You can achieve your requirement by enabling RowSelectionBrush and SelectionForegroundBrush property. Please refer the below code snippet, 
 

private void Button_Click_1(object sender, RoutedEventArgs e) 
{ 
    gridB.RowSelectionBrush = new SolidColorBrush(Colors.Bisque); 
    gridB.SelectionForegroundBrush = new SolidColorBrush(Colors.Red); 
} 


 

Please let us know if you have any query. 

Regards, 
Muthukumar K 


Loader.
Live Chat Icon For mobile
Up arrow icon