Error, CellRowColumnIndex is only accessible when renderer is current cell

Hi,

Could you give me some insight on what this error means and why it might happen?

This happens very rarely when I click on a ComboBox cell. It has a custom implementation, which I use to ensure that the ComboBox cell begins editing and the ComboBox opens up when the cell is clicked. The column is called the "Flag" column.

I have also overriden the selection controller with a custom implementation of HandlePointerOperations()

CellRowColumnIndex is only accessible when renderer is current cell. Check GridRenderStyleInfo.CellRowColumnIndex instead.
System.InvalidOperationException: CellRowColumnIndex is only accessible when renderer is current cell. Check GridRenderStyleInfo.CellRowColumnIndex instead.
   at Syncfusion.UI.Xaml.Grid.Cells.GridCellRendererBase.get_CurrentCellIndex()
   at Syncfusion.UI.Xaml.Grid.Cells.GridCellComboBoxRenderer.SelectionChangedinComboBox(Object sender, SelectionChangedEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.Controls.ComboBox.OnSelectionChanged(SelectionChangedEventArgs e)
   at System.Windows.Controls.Primitives.Selector.SelectionChanger.SelectJustThisItem(ItemInfo info, Boolean assumeInItemsCollection)
   at System.Windows.Controls.ComboBox.NotifyComboBoxItemMouseUp(ComboBoxItem comboBoxItem)
   at System.Windows.Controls.ComboBoxItem.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)


public class CustomComboBoxCellRenderer : GridCellComboBoxRenderer
{
    public override void OnInitializeEditElement(DataColumnBase dataColumn, ComboBox uiElement, object dataContext)
    {
        base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
        uiElement.Style = Application.Current.MainWindow.Resources["ComboBoxStyle"] as Style;
    }


    protected override void OnEditElementLoaded(object sender, RoutedEventArgs e)
    {
        base.OnEditElementLoaded(sender, e);
        if (sender is ComboBox comboBox) comboBox.IsDropDownOpen = true;
    }
}


public override void HandlePointerOperations(GridPointerEventArgs args, RowColumnIndex rowColumnIndex)

{
    var offset = DataGrid.ShowRowHeader ? -1 : 0;
    var isDataColumn = rowColumnIndex.ColumnIndex + offset >= 0;


    // Check if this was a right click on a searchable cell, and cancel
    if (args.Operation == PointerOperation.Tapped && args.OriginalEventArgs is MouseButtonEventArgs { ChangedButton: MouseButton.Right } && isDataColumn)
    {
        var column = DataGrid.Columns[rowColumnIndex.ColumnIndex + offset];


        if (BrokerSheetGrid.FastSearchColumns.Contains(column.MappingName))
        {
            return;
        }
    }


    // Base implementation
    base.HandlePointerOperations(args, rowColumnIndex);


    // Start the editor immediately if a Flag column cell is tapped.
    if (args.Operation == PointerOperation.Tapped && isDataColumn)
    {
        var column = DataGrid.Columns[rowColumnIndex.ColumnIndex + offset];


        if (column.MappingName == nameof(QuoteModel.Flag)
            && args.OriginalEventArgs is MouseButtonEventArgs { ChangedButton: MouseButton.Left })
        {
            TryBeginEdit();
        }
    }
}

private bool TryBeginEdit()
{
    // Check if edit item is already set in view and cancel edit if it is.
    if (DataGrid.View.IsEditingItem || DataGrid.View.CurrentEditItem != null)
    {
        CurrentCellManager.EndEdit(false);
    }


    try
    {
        return CurrentCellManager.BeginEdit();
    }
    catch (InvalidOperationException ex)
    {
        LogManager.GetCurrentClassLogger().Error(ex, "Failed to begin edit");
        return false;
    }
}

1 Reply

SG Santhosh Govindasamy Syncfusion Team December 18, 2024 10:48 AM UTC

Hi Zia,

Thank you for reaching out.


From the provided information and code snippet, we attempted to replicate the exception on our end, but we were unable to do so. The reported exception did not occur, and it worked as expected.


Based on the provided code snippet, our understanding is that your requirement is to open the combobox dropdown with a single tap. You have properly overridden the combobox renderer and correctly handled the HandlePointerOperations method, which is commendable. If you want to open a combobox dropdown with a single tap, you can also use the CellTapped event and begin editing the current cell based on the column.


Code Snippet:

public MainWindow()

{

    InitializeComponent();

    this.dataGrid.CellRenderers.Remove("ComboBox");

    this.dataGrid.CellRenderers.Add("ComboBox", new GridCellComboBoxRendererExt());

    //this.dataGrid.SelectionController = new GridSelectionControllerExt(this.dataGrid);

    dataGrid.CellTapped += DataGrid_CellTapped;

}

private void DataGrid_CellTapped(object sender, GridCellTappedEventArgs e)

 {

     if(e.Column.MappingName== "Country")

     {

         if(dataGrid.SelectionController!=null)

             dataGrid.SelectionController.CurrentCellManager.BeginEdit();

 

     }

 }



If we misunderstood your requirement, please provide more details. For your reference, we have attached the modified sample and video.

Regards,
Santhosh.G


Attachment: SfDataGrid_Demo_910af4cc.zip

Loader.
Up arrow icon