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.
Unfortunately, activation email could not send to your email. Please try again.

2 questions on SfDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

129776 Apr 3,2017 07:37 AM Apr 4,2017 12:24 PM WPF 1
loading
Tags: SfDataGrid
Dov
Asked On April 3, 2017 07:37 AM

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.

            

Muthukumar Kalyanasundaram [Syncfusion]
Replied On April 4, 2017 12:24 PM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;