Issue using custom style select in DataGrid

Posted by: lukirito15 on 4 July 2018, 9:03 pm EST

    • Post Options:
    • Link

    Posted 4 July 2018, 9:03 pm EST

    Hi all and GrapeCity support team,

    I have a problem with select custom style set background for DataGridCellPresenter

    When form initialization, background color is correct for cell when i set. But when i scroll down and up, another cell without set background change to cell have color background

    Is this bug? Please review and feedback for me! Thanks all :smiley:

    Here is sample project

    https://goo.gl/xYsZWb

  • Posted 4 July 2018, 9:09 pm EST

    Here is my sample :smiley:

    SampleStyleSelector.zip

  • Posted 5 July 2018, 9:28 pm EST

    Hi,

    I am able to observe the discrepancy in row background upon scrolling the grid. However, upon debugging the application, the cause of this behavior was when model with AccountBackGround other than Plum/LightPink/Orange was passed there was no specific Style returned which is why the grid was showing randomly any Style. Returning a default style for else part fixed the issue at my end.

    public override Style SelectStyle(object item, DependencyObject container)
    {
           var model = item as DataItemComponent;
           if (model != null)
           {
               if (model.AccountBackGround == "Plum")
               {
                    return PlumCellTemplate;
               }
               else if (model.AccountBackGround == "LightPink")
               {
                    return LightPinkCellTemplate;
               }
               else if (model.AccountBackGround == "Orange")
               {
                    return OrangeCellTemplate;
               }
               [b]else
               {
                    return NormalCellTemplate;
               }[/b]
           }
           return null;
    }
    ```[b]Xaml[/b]```
    <[b]c:CheckResultStyleSelector.NormalCellTemplate>
         <Style TargetType="c1:DataGridCellPresenter">
            <Setter Property="Background" Value="{Binding C1DataGridExtension.RowBackground}" />
         </Style>
     </c:CheckResultStyleSelector.NormalCellTemplate>[/b]
    ```Please verify the fix using the attached modified sample application.
    
    Regards,
    Ruchir
     [zip filename="SampleStyleSelector_modified.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-2e56c312-ed8e-43a2-b444-be0818e9f0a0.zip[/zip]
  • Posted 8 July 2018, 3:51 pm EST

    Hi Ruchir.Agarwal,

    Thanks you for reply and fix issue for me. This perfect solution for me :smiley:

    Thanks you very much!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels