Loose Focus and selected row in RadGridView

1 Answer 25 Views
GridView ListBox
Romain
Top achievements
Rank 2
Iron
Iron
Romain asked on 16 Aug 2022, 07:50 PM | edited on 16 Aug 2022, 08:05 PM

Hi,

I use a RadGridView to display a collection of object. I use it for display only, no user input needed except for a button in the last column.

Why I use this control for such display and not a ListBox: a ListBox would require me to create an ItemTemplate but I need to keep constant columns width between my object properties so I can have a consistent alignment for all items. Also the columns should always be set to the largest control within it.

I remove most features that makes it look like a table: 

<telerik:RadGridView x:Name="radGridView"
                                 ItemsSource="{Binding Items}"
                                 ShowColumnHeaders="False" ShowGroupPanel="False"
                                 RowIndicatorVisibility="Collapsed"
                                 AlternateRowBackground="Transparent"
                                 AutoGenerateColumns="False"
                                 GridLinesVisibility="None"
                                 CanUserFreezeColumns="False" CanUserReorderColumns="False"
                                 CanUserSelectColumns="False">

I also set CanUserSelect="False" and  IsSynchronizedWithCurrentItem="False" but that didn't seem to work...

The last step would be to remove the selection and its display. I would like to remove the focus and color change when click on a row. I tried to set IsHitTestVisible = "False" but it prevent me to use my buttons in the last column.. 

                                

Any suggestions ?

Thank you for your help

1 Answer, 1 is accepted

Sort by
1
Accepted
Stenly
Telerik team
answered on 19 Aug 2022, 03:39 PM

Hello Romain,

One way of achieving this behavior is by extracting the default control template of the GridViewRow element. Then, modify the BorderBrush property of both the x:Name="Background_Over" and x:Name="Background_Selected" Border elements (for example, you could set it to White). Create a new Style with TargetType="GridViewRow" and set the modified template to its Template property. Include an additional Setter for the MouseOverBackground and set it to the desired color (White is a possible option). After that, create a new Style with TargetType="GridViewCell" and modify the CurrentBorderBrush property by setting a new value. Finally, set the CanUserSelect property to False and IsReadOnly to True of the RadGridView control.

After applying these suggestions the following result should be present:

I have attached a sample project, which has the above suggestions applied. The default control template of the GridViewRow element is extracted from the Office_Black theme.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Romain
Top achievements
Rank 2
Iron
Iron
commented on 19 Aug 2022, 03:56 PM

Works like a charm !! 
Thank you so much for your help. 
Tags
GridView ListBox
Asked by
Romain
Top achievements
Rank 2
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or