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
close icon

Handling Selection And Deselection of a row

Hi,
 I am using sfDatagrid to show some data of users, above the grid I have a Edit button which is by default in Disable mode. When user selects a row in data grid the Edit button will be Enabled. When user clicks again on same row the button will be Disabled again. Please how to handle this, when clicks on row it should be with some background color and click on the same again background color should be clear to normal.

Thanks in advance
Regards.  

1 Reply

MK Muthukumar Kalyanasundaram Syncfusion Team April 21, 2017 12:52 PM UTC

Hi Murali, 

Thank you for contacting Syncfusion support. 

We have analyzed your query. You can achieve your requirement by overriding the SelectionController class as show like the below code, 

Code Snippet: 

this.dataGrid.SelectionController = new GridSelectionControllerExt(this.dataGrid); 
 
internal class GridSelectionControllerExt : GridSelectionController 
{ 
    public GridSelectionControllerExt(SfDataGrid datagrid) : base(datagrid) 
    { 
 
    } 
 
    private bool isSelectedRow = false; 
    int prevSelectionIndex = 0; 
    protected override void ProcessPointerPressed(PointerRoutedEventArgs args, RowColumnIndex rowColumnIndex) 
    { 
        base.ProcessPointerPressed(args, rowColumnIndex);            
        var currentRowIndex = rowColumnIndex.RowIndex; 
        if (currentRowIndex != prevSelectionIndex) 
        { 
            if (!isSelectedRow) 
                isSelectedRow = true; 
            else 
                isSelectedRow = false; 
            prevSelectionIndex = currentRowIndex; 
 
            (this.DataGrid.DataContext as UserInfoViewModel).EditButtonVisible = true; 
        } 
        else 
        { 
            this.DataGrid.SelectedItems.Clear(); 
            isSelectedRow = false; 
            (this.DataGrid.DataContext as UserInfoViewModel).EditButtonVisible = false; 
        }  
    } 
} 



Please let us know if you have any query. 

Regards, 
Muthukumar K 


Loader.
Live Chat Icon For mobile
Up arrow icon