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.

Virtualization + GridTemplateColumn + Binding = recycling cell issue...

Thread ID:

Created:

Updated:

Platform:

Replies:

128002 Dec 23,2016 12:07 PM Jan 3,2017 08:40 AM WinRT 5
loading
Tags: SfDataGrid
Djooleean
Asked On December 23, 2016 12:07 PM

Hello guys,

I got a problem with the sfDataGrid control. 
The short description is: 
- in my grid I use a "GridTemplateColumn" with a "CellTemplateSelector"
- one of my template is a "sfNumericUpDown": I bind Value, Maximum & Minimum values directly with the 'DataContext'
- >> I set some values on top cells - I scroll down and "new cells" appear, old ones disappear => when I scroll back to the top of the datagrid, cell values havec changed !
==> It looks like the new values match the "Maximum" value of bottom cells !

That's why I think, my cell are recycled to display the bottom ones but (I don't know how) the value of top cells are changed when they disappear corresponding on the 'Maximum' binding of the bottom cells...
I join the 3 steps images below (step 1: I set values on top cells, step 2: I scroll down, step 3: I scroll back to the top --> 1st cell has a new value corresponding to the Maximum of the bottom cell)
Step 1 Step 2Step 3



Here is some code details:

The datagrid's column definition:

                        <syncfusion:GridTemplateColumn Width="220"

                                                       VerticalAlignment="Center"

                                                       AllowSorting="False"

                                                       CellTemplateSelector="{StaticResource RuptureTemplateSelector}"

                                                       ColumnSizer="SizeToCells"

                                                       HeaderText="{CustomResource NewCommandePage_QuantitiesHeader}"

                                                       TextAlignment="Center" 

                                                       />


The column template used:

            <SfInput:SfNumericUpDown syncfusion:FocusManagerHelper.FocusedElement="True"

                                     LargeChange="{Binding Produit.QteMini}"

                                     Maximum="{Binding Converter={StaticResource MaximumCommandeProduitConverter}, Mode=OneWay}"

                                     Minimum="0"

                                     SmallChange="{Binding Produit.QteMini}"

                                     Style="{StaticResource IntNumericUpDown}"

                                     Value="{Binding QuantiteCommandee, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 

                                     />




-> I tried to disable "AllowRecycle" on renderers with no success... 

            var rdr = (uiArticlesGrid.CellRenderers["Template"] as GridCellTemplateRenderer);

            rdr.AllowRecycle = false;

            rdr.IsEditable = true;


-> I didn't use 'MappingName' on the grid template column... 


Any suggestion, about virtualization / recycling, using DataContext binding on cell templates ?
Maybe should I not use direct DataContext binding on template cells & use MappingName ? (but how Can I bind Maximum, Minimum ?)


Thanks in advance !
Regards, Julien








Jai Ganesh S [Syncfusion]
Replied On December 27, 2016 07:25 AM

Hi Julien, 
We suspect that, you want to bind the vales to GridUpDownColumn.  We already have a kb for binding the values to GridUpDownColumn by customizing GridCellUpDownRenderer. 
Regards, 
Jai Ganesh S 


Nicolas
Replied On December 27, 2016 11:51 AM

Hi,

No, we don't want use GridUpDownColumn, because you need to select the cell first to tappe on "+" or "-" button.
We need to have this button directly available.

We have an issue with AllowRecycle feature.
How to disable it ?
Or How to trigger no events during the binding process ?

Regards,

Jai Ganesh S [Syncfusion]
Replied On January 2, 2017 07:39 AM

Hi Julien,, 
Sorry for the delay. The Updown column value and maximum values are changed by changing the ItemsSource. We have resolved this by setting the value and maximum value by using behavior like below, 
  <Grid:GridTemplateColumn MappingName="EmployeeAge" Width="250"> 
                    <Grid:GridTemplateColumn.CellTemplate> 
                        <DataTemplate> 
                            <editors:SfNumericUpDown Grid:FocusManagerHelper.FocusedElement="True" 
                                                     DataContext="{Binding}" 
                                    Minimum="0"> 
                                <i:Interaction.Behaviors> 
                                    <i:BehaviorCollection> 
                                        <local:GridBehavior/> 
                                    </i:BehaviorCollection> 
                                </i:Interaction.Behaviors> 
                            </editors:SfNumericUpDown> 
                        </DataTemplate> 
                    </Grid:GridTemplateColumn.CellTemplate> 
   </Grid:GridTemplateColumn> 
 
 
   public class GridBehavior : DependencyObject, IBehavior 
    { 
        SfNumericUpDown upDown; 
        public DependencyObject AssociatedObject 
        { 
            get 
            { 
                return upDown; 
            } 
        } 
 
         
 
        public void Attach(DependencyObject associatedObject) 
        { 
            upDown = associatedObject as SfNumericUpDown; 
            upDown.Loaded += UpDown_Loaded; 
            upDown.DataContextChanged += UpDown_DataContextChanged; 
            upDown.ValueChanged += UpDown_ValueChanged; 
        } 
 
        private void UpDown_ValueChanged(object sender, ValueChangedEventArgs e) 
        { 
            if (upDown.DataContext == null || isinsuspend) 
                return; 
            int updownval = 0; 
 
            if (upDown.Value != null) 
                int.TryParse(upDown.Value.ToString(), out updownval); 
            (upDown.DataContext as BusinessObjects).EmployeeAge = updownval; 
        } 
 
        bool isinsuspend = false; 
        private void UpDown_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args) 
        { 
            if (upDown.DataContext == null) 
                return; 
 
            isinsuspend = true; 
            var _maxval = (upDown.DataContext as BusinessObjects).Maximum; 
            var _val = (upDown.DataContext as BusinessObjects).EmployeeAge; 
 
            upDown.Maximum = _maxval; 
            upDown.Value = _val; 
            isinsuspend = false; 
        } 
 
        private void UpDown_Loaded(object sender, RoutedEventArgs e) 
        { 
            if (upDown.DataContext == null) 
                return; 
 
            isinsuspend = true; 
            var _maxval = (upDown.DataContext as BusinessObjects).Maximum; 
            var _val = (upDown.DataContext as BusinessObjects).EmployeeAge; 
 
            upDown.Maximum = _maxval; 
            upDown.Value = _val; 
            isinsuspend = false; 
        } 
 
        public void Detach() 
        { 
            upDown.Loaded -= UpDown_Loaded; 
            upDown.DataContextChanged -= UpDown_DataContextChanged; 
            upDown.ValueChanged -= UpDown_ValueChanged; 
        } 
    } 
 
 
Regards, 
Jai Ganesh S 


Djooleean
Replied On January 2, 2017 08:35 AM

Ok thanks for the tips !

=> finally I used a traditional GridUpDownColumn with a custom template Cell
=> & I made a new UpDown cell renderer where I can also bind MinValue & MaxValue (on OnWireEditeUIElement \ uiElement.DataContextChanged)
So that it is ok for me.

But for my initial problem:
- in fact I would like a cell (custom UpDown cell) that is "always" in edit mode...
- when I do that "Value" is not correctly handled with I presume a recycling issue (as I explained above)

So, my last question is there a way to automatically set a cell to "Edit" mode when I change of row in a SfDataGrid ?
For instance, for a GridUpDownColumn, I would like to directly see the underlying SfNumericUpDown of this column when I change of row.

Thanks again,
Julien

Jai Ganesh S [Syncfusion]
Replied On January 3, 2017 08:40 AM

Hi Julien, 
We regret to inform you that, you cannot displaying the GridUpDownColumn as in edit mode when the row changed . This is the default behavior of our SfDataGrid. However, as we said in our previous update,you can load the SfNumericUpDown inside the GridTemplateColumn and go to edit mode while we click the cell. 
Regards, 
Jai Ganesh S 


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.

;