Selected item color exception

I'm trying to change the selected item background color, but when I tapped on an item the grid throw an exception.

GridSelectionController

public CustomSelectionController(SfDataGrid datagrid)
        {
            this.DataGrid = datagrid;
        }
        
        public override Color GetSelectionColor(int rowIndex, object rowData)
        {
            return Color.FromHex("#F89829");
        }

I'm binding it like this:
dataGridVersus.SelectionController = new CustomSelectionController(dataGridVersus);
                    SelectionMode = SelectionMode.Multiple;

The exception:

Object reference not set to an instance of an object.
   at Syncfusion.SfDataGrid.XForms.GridSelectionController.ProcessingPointerTouchUp(RowColumnIndex rowColumnIndex)
   at Syncfusion.SfDataGrid.XForms.GridSelectionController.HandlePointerOperation(GridPointerEventArgs args, RowColumnIndex rowColumnIndex)
   at Syncfusion.SfDataGrid.XForms.DataColumnBase.RaisePointerTouchUp()
   at Syncfusion.SfDataGrid.XForms.UWP.GridCellBaseRenderer.OnTapped(Object sender, TappedRoutedEventArgs e)
   at Windows.ApplicationModel.Core.UnhandledError.Propagate()

1 Reply

SS Sivaraman Sivagurunathan Syncfusion Team February 23, 2018 12:37 PM UTC

Hi Juan, 
 
Thanks for using syncfusion support. 
 
We have checked your query. We have notice that in your code snippet, you did not call the base in the CustomSelectionController constructor. 
You need to call the base in CustomSelectionController constructor. We have prepared the sample based on your requirement and attached for your reference you can download the same from below link. Also refer the UG link. 
 
 
dataGrid.SelectionController = new CustomSelectionController(dataGrid); 
 
public class CustomSelectionController : GridSelectionController 
{ 
 
    public CustomSelectionController(SfDataGrid data):base(data) 
    { 
        this.DataGrid = data; 
    } 
    public override Color GetSelectionColor(int rowIndex, object rowData) 
    { 
        return Color.FromHex("#F89829"); 
    } 
} 
 
 
  
Regards, 
Sivaraman  


Loader.
Up arrow icon