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

UpdateDatarow clears the CurrentCell of the CurrentCellManager

I'm using a SfDataGrid and set up the EditTrigger = OnTap.
I realized that in spite of that configuration, the EditTrigger OnTap did not work when you move from an editing cell to another, but worked when the previous selected cell was not in edit mode.
As I was not sure why this was happening, I changed EditTrigger to DoubleTap and tried to trigger manually the BeginEdit in the SelectionChanged event (I also tried in the CellActivated event). 
But in those cases, every time I was coming from an editing cell, datagrid.SelectionController.CurrentCellManager.BeginEdit() had no effect and also datagrid.SelectionController.CurrentCellManager.CurrentCell happened to be null.
Finally I found out the reason: I'm using a custom CellStyleSelector to change the style of the cell in runtime, just as it is described here:

https://www.syncfusion.com/kb/5992/how-to-change-the-gridcell-style-at-runtime

BUT with the slight difference that I'm doing that in CurrentCellEndEdit instead of CurrentCellActivated, because I need to set the cell background to red or white according to a complex backend validation after the content is edited.
If I comment the UpdateDataRow, line, both the EditTrigger OnTap and the solution I tried after that work ok, but of course the style of the cell is not updated.

So, to summarize, the call to UpdateDataRow seems to be messing with the "selected cell", and this affect the SelectionController and also the OnTap feature that I guess uses the SelectionController to work.

I don't know if this is a bug or it's just how the UpdateDataRow should work. Is any way other than UpdateDataRow to update the style of the cell?
Anyway, if you consider that he CurrentCell of the SelectionController should be preserved disregarding any call to UpdateDataRow and decide to include that behaviour in next releases, it would also be great ;)

Thanks in advance for any advice, I really appreciate the outstanding support given by you to Syncfusion products.

Greetings, 

Fernando

5 Replies

BR Balamurugan Rajaraman Syncfusion Team March 13, 2017 02:00 PM UTC

HI Carios. 

Thank you for contact Syncfusion support. 

We have analyzed your query “Update Data row clears the current cell”.  Could you please share more information about how styles are applied in GridCell in your application. It would be helpful for us to analyze further. 

Regards, 
Balamurugan R 



CF Carlos Fernando Consigli March 13, 2017 03:24 PM UTC

Hi, Balamurugan. Thanks for your quick answer.
I'm using a StyleSelector. However, I just tried removing it, and the issue is still reproducible. I'm using this code:

newDatagrid.EditTrigger = EditTrigger.OnTap;
//newDatagrid.CellStyleSelector = new CellStyleSelector();
newDatagrid.CurrentCellEndEdit += newDatagrid_CurrentCellEndEdit;
....
private void newDatagrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs args)
        {
            var grid = sender as SfDataGrid;
            var cell = (grid.SelectionController.CurrentCellManager.CurrentCell.Renderer as GridCellRendererBase).CurrentCellElement;
            if (cell != null)
            {
                grid.UpdateDataRow(args.RowColumnIndex.RowIndex);
            }
        }

and that call to UpdateDataRow is what is breaking the OnTap edit trigger.

Greetings,

Fernando


BR Balamurugan Rajaraman Syncfusion Team March 15, 2017 01:23 AM UTC

Hi Fernando, 

We have analyzed your query “Update Data row clears the current cell of the current cell manger” . you can able to achieve your requirement by updating the style for the current cell In the  CurrentCellEndEdit Event by using Dispatcher  as like the below provide code sample. 

private void DataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e) 
        { 
            System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => 
            { 
                var grid = sender as SfDataGrid; 
                //getting GridCell 
                var cell = (grid.SelectionController.CurrentCellManager.CurrentCell.Renderer as GridCellRendererBase).CurrentCellElement; 
                if (cell != null) 
                { 
                    var vm = cell.DataContext as OrderInfo; 
                    //assigned columnindex to the index property in OrderInfo 
                    vm.DataIndex = e.RowColumnIndex.ColumnIndex; 
                   // updates the current row index 
                    grid.UpdateDataRow(e.RowColumnIndex.RowIndex); 
                } 
            }), System.Windows.Threading.DispatcherPriority.ApplicationIdle); 
        } 

For your reference  we have attached the sample for your reference. 


Regards, 
Balamurugan R


CF Carlos Fernando Consigli March 30, 2017 03:06 PM UTC

Excellent! thanks a lot, it worked perfectly. Sorry for my delayed update on the issue.


BR Balamurugan Rajaraman Syncfusion Team March 31, 2017 04:18 AM UTC

Hi Fernando 

Thank you for the Update. 

Please let us know if you have any further assistance on this. 

Regards, 
Balamurugan R 


Loader.
Live Chat Icon For mobile
Up arrow icon