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.

Selected Cell Background

Thread ID:

Created:

Updated:

Platform:

Replies:

116921 Jun 30,2014 05:10 PM Jul 17,2014 07:39 AM WPF 5
loading
Tags: GridDataControl
Yu
Asked On June 30, 2014 05:10 PM

Hi,
 
With VisualStyle="DefaultOffice2007Blue" for the GridDataControl,  when a cell is selected, the whole row will be highlighed with the cell's boarder become grey.
 
Is it possible to change the behavior to not highlight the row and only use Red for the selected cell's background color?
 
 
Thanks
 
Yu

 


Deepak Raj Sundar [Syncfusion]
Replied On July 8, 2014 07:58 AM

Hai Yu,

Thanks for using Syncfusion products and sorry for the delay. It is possible to select a particular cell alone without highlighting other cells of same row, by setting  AllowSelection="Cell" and ListBoxSelectionMode="None" in the GridDataControl . In order to make the Background color of selected cell as red, you can create a resource dictionary and refer it in GridDataControl  resources.

Please refer the following code example :

Code Snippet[XAML] :

Inside File ‘Resource1.xaml’ :

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

                    xmlns:syncfusion="http://schemas.syncfusion.com/wpf">

    <syncfusion:GridDataStyleManager x:Key="CustomGridDataStyleManager">

        <syncfusion:GridDataStyleManager.RowAppearence>

            <syncfusion:RowAppearence CurrentCellSelectionBackground="Red"                 

                                                               CurrentCellSelectionForeground="Black" />

        </syncfusion:GridDataStyleManager.RowAppearence>

    </syncfusion:GridDataStyleManager>

</ResourceDictionary>

 

Inside MainWindows.xaml :

 

<syncfusion:LayoutControl.Resources>

     <ResourceDictionary  Source="/BasicSortingDemo;component/Resources/Resource1.xaml" />

</syncfusion:LayoutControl.Resources>

<syncfusion:GridDataControl x:Name="dataGrid1"

                                        AllowSelection="Cell"

                                        AutoPopulateColumns="False"

                                        AutoPopulateRelations="False"

                                        ColumnSizer="Star"

                                        ItemsSource="{Binding ProductInfo}"

                                        ListBoxSelectionMode="None"

                                        ShowGroupDropArea="False"

                                        ShowSortNumber="{Binding Path=IsChecked,

                                                                 ElementName=sortNumber}"

                                        StyleManager="{StaticResource CustomGridDataStyleManager}"

                                        VisualStyle="Office14Blue" >

 


Regards,

Deepak raj Sundar


Attachment: CS_84e6a301.zip

Yu
Replied On July 8, 2014 03:09 PM

Hi, thanks for the reply.

Allowselection and listboxselectionmode work well to disable the row selection and only highlight the selected cell.

However, as we are binding the grid to a datatable as the datasource to allow dynamic number of columns during runtime, the style manager approach does not seem to work for changing the colours of selected cell. I also tried dynamic resource instead of static resource, but the cell colour still can not be changed. There is no column declaration in the xaml.

Will there be a work around for it? Also, is it possible to set the text alignment of these dynamic generated columns?

Thanks





Deepak Raj Sundar [Syncfusion]
Replied On July 15, 2014 02:39 AM

Hai Yu,

Sorry for the delay caused. We have created a sample in which the data source is a Data Table and cell BackGround color is changed on selection.

Please refer the Sample attached and the following code snippet.

 

Code Snippet[Xaml]:

Inside the Dictionary1.xaml file :

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

                    xmlns:syncfusion="http://schemas.syncfusion.com/wpf">

    <syncfusion:GridDataStyleManager x:Key="CustomGridDataStyleManager">

        <syncfusion:GridDataStyleManager.RowAppearence>

            <syncfusion:RowAppearence

                                       HighlightSelectionBackground="Red"

                                      CurrentCellSelectionForeground="Black"

                                        TextBlock.TextAlignment="Justify"  />

        </syncfusion:GridDataStyleManager.RowAppearence>     

    </syncfusion:GridDataStyleManager >  

</ResourceDictionary>

 

Please Let us know if you have any concern.

 

Regards,

Deepak raj Sundar.


Attachment: Data_Table_Demo_13f15b5a.zip

Yu
Replied On July 15, 2014 06:51 AM

Hi,
 
The sample works becuase it has the columns pre-dfined in the xaml.
 
If the columns definition are removed, and use the DataTable to generate the columns dynamics, the style settings will not work.
 
Could you please advise?
 
Thanks

Deepak Raj Sundar [Syncfusion]
Replied On July 17, 2014 07:39 AM

Hi Yu,

We have modified the sample , without column definitions and we are getting the style settings i.e. the background color of selected cell gets changed to red.

Please have a look to the attached sample and let us know if you have any concern.

Regards,

Deepak raj Sundar.


Attachment: Dynamic_Data_Table_Demo_57b68e4e.zip

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.

;