lose selection hight light after using StyleSelector

I am using  StyleSelector successful setting  the GridCell.BackgroundProperty,

but the cell lose selection Highlight after the StyleSelector,

try to add  GridCell.CellSelectionBrushProperty with other Brush but still fail to show the Brush.

how to show to Selection highlight again?

Also when ShowRowHeader is true SFDataGrid the gridcell lose the style setby StyleSelector ,


    public class CustomCellStyleSelector : StyleSelector

    {

        public override Style SelectStyle(object item,DependencyObject container)

        {

                GridCell gridCell = container as GridCell;

                var mappingName = gridCell.ColumnBase.GridColumn.MappingName;

                int col_index = gridCell.ColumnBase.ColumnIndex;

                DataRowView drv = gridCell.DataContext as DataRowView;

                string str = (drv[col_index].ToString());

                if(str=="something")

                {

                    var style_ReadOnly = new Style(typeof(GridCell));

                    Setter setter = new();

                    setter.Property=GridCell.BackgroundProperty;

                    setter.Value=Brushes.WhiteSmoke;

                    Setter setter1 = new();

                    setter1.Property=GridCell.CellSelectionBrushProperty;

                    setter1.Value=Brushes.DarkOrange;

                    style_ReadOnly.Setters.Add(setter);

                    style_ReadOnly.Setters.Add(setter1);

                    return style_ReadOnly;

                }

                return base.SelectStyle(item,container);

        }

    }

Row Selection on RED 「」 but after  StyleSelector Cell not show high light of selection.



6 Replies 1 reply marked as answer

JO Johnes November 2, 2021 03:21 PM UTC

ok i know why  ShowRowHeader  is disappear my  StyleSelector setting,

because it's add one in to the column index.

but i still don't know how to show the selection highlight again.



JO Johnes November 2, 2021 04:02 PM UTC

try to Display the row index in row header

https://help.syncfusion.com/wpf/datagrid/rows?cs-save-lang=1&cs-lang=csharp#display-the-row-index-in-row-header

this page sample is not working 

http://www.syncfusion.com/downloads/support/directtrac/general/ze/WPF-13678149272112665828.zip

I just wonder where is the XAML style code should be place ?

can't put under the Syncfusion:SfDataGrid.



JO Johnes November 3, 2021 09:01 AM UTC

When the datagrid.ItemsSource= Datatable.DefaultView

i found that if the datatable columns name with a dot(.) on it

the font color will be the same with background color.

3.2.1 has a value aaasd but can't see it because the color is the still,

but when the column name as 321 it's working fine




MA Mohanram Anbukkarasu Syncfusion Team November 3, 2021 02:05 PM UTC

Hi Johnes, 

Thanks for contacting Syncfusion support.  

#Regarding the selection background issue while setting style for the cells 
 
We would like to let you know that the Row/Cell selection border is behind the GridCell content. So when you apply the background for GridCell, the selection is not displayed in UI.Please refer the below given KB document to resolve this.  


#Regarding the issue reported in the filter control 
 
We regret to let you know that we are unclear about the issue you are reporting in the filter control. Kindly revert to us with more detail about the problem with more illustration. It will be more helpful for us to understand the exact issue and to provide prompt solution.  

Regards, 
Mohanram A. 



JO Johnes replied to Mohanram Anbukkarasu November 3, 2021 02:25 PM UTC

Hello thanks for the reply

about the second problem that is not a filter problem control.


that is about when binding DataTable as ItemsSource to SfDataGrid.

if my DataTable add the Columns with a dot in the name on it.

the value under the that columns is still here,

 that can be show on the filter but not showing on the SfDataGrid visibly.



dataTable.Rows.Add(StringValue.ToArray());

datagrid.ItemsSource=dataTable.DefaultView;




MA Mohanram Anbukkarasu Syncfusion Team November 4, 2021 05:52 AM UTC

Hi Johnes, 

Thanks for the update.  

We are able to understand the problem. On further analysis we have found that it is the behavior of the DataTable. We have checked this with framework default DataGrid control and the same behavior exists in it. However if your requirement is only to have column header with a dot in it, you can achieve it by defining the column name in the DataTable without dot and set HeaderText property of the corresponding column with dot.  


 

Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon