Using a converter seems to disable the cell selection settings

I am using a converter, as documented at https://help.syncfusion.com/wpf/datagrid/conditional-styling to conditionally format the rows in my sfDataGrid.  My XAML is:

<TabItem x:Name="TokenStreamTab" Header="Parsed">
    <TabItem.Resources>
        <self:ParserColorConverter x:Key="converter" />
        <Style TargetType="Syncfusion:GridCell">
            <Setter Property="Background" Value="{Binding Converter={StaticResource converter}}" />
        </Style>
    </TabItem.Resources>
    <Syncfusion:SfDataGrid
        x:Name="tokenisedGrid"
        AllowDraggingColumns="True"
        AllowResizingColumns="True"
        AllowTriStateSorting="True"
        ColumnSizer="Auto"
        Foreground="Black"
        GridCopyOption="IncludeHeaders"
        SelectionMode="Extended"
        SelectionUnit="Cell"
        ShowBusyIndicator="True"
        ShowGroupDropArea="True"
        ShowRowHeader="True"
        ShowSortNumbers="True" />
</TabItem>


If I remove the <TabItem.Resources> cell selection works as expected.  With it, the cells recolour correctly but cannot be selected - I just get the bold rectangle round the currently selected cell.  If I attempt a click and drag, the bold rectangle round the cell simply moves with the mouse cursor, but no cell range selection is made.

I don't think this is the intended behaviour for the control, so I guess I must be doing something incorrectly?


TIA


3 Replies

VS Vijayarasan Sivanandham Syncfusion Team November 28, 2022 05:37 PM UTC

Hi Peter,

We have checked the provided code snippet from our end. You are applying the CellStyle in SfDataGrid. So, when you apply the background for GridCell, the selection is not displayed in the UI. 


However, you can overcome this problem by reducing the opacity of the brush that you set to the GridCell background. Refer to the below code snippet,

public class ParserColorConverter : IValueConverter

{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

        var input = value as OrderInfo;

 

        //custom condition is checked based on data.

 

        if (input.OrderID < 1003)

            //Here define the Opacity for the SolidColorBrush

            return new SolidColorBrush(Colors.LightBlue) { Opacity=0.5};

 

        else if (input.OrderID < 1007)

            //Here define the Opacity for the SolidColorBrush

            return new SolidColorBrush(Colors.Bisque) { Opacity = 0.5 };

 

        else

            return DependencyProperty.UnsetValue;

    }

 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

        throw new NotImplementedException();

    }

}


Find the sample in the attachment.


For more information, refer to the below knowledge base documentation link:


KB Link: https://www.syncfusion.com/kb/3182/how-to-show-the-selection-of-row-cell-when-setting-the-background-for-sfdatagrid-gridcell

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_4b841c15.zip


PE Peter November 28, 2022 06:47 PM UTC

Thank you so much for your reply.  Yes, I can see that reducing the opacity shows the selected cells.  However, I do have to compromise on my desired cell background colours.

Also, and I'm afraid I couldn't get your sample to compile, but although a selection rectangle is now shown, Ctrl+C does not copy the selected cells to the clipboard.  I have:

                        GridCopyOption="IncludeHeaders"

                        SelectionMode="Extended"

                        SelectionUnit="Cell"

So I don't understand why the copy functionality is not working.  I have another sfDataGrid in the application with the same settings but no converter and Ctrl+C works as expected there.




VS Vijayarasan Sivanandham Syncfusion Team November 29, 2022 05:23 PM UTC


Loader.
Up arrow icon