This is a migrated thread and some comments may be shown as answers.

How to hide the cell focus rect?

15 Answers 455 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 17 Mar 2009, 01:19 AM
I know this should be easy, but I'm still a bit lost in all the GridViewXXX classes ;-)

I need to hide the focus rectangle that shows up when a cell is clicked. Most of my grids are read only, so the focus rect makes no sense and is visually distracting.

I'm sure it's just a question of overriding a default style on something, but I'm not finding it. A quick pointer in the right direction should be all I need.

Thanks,
Roger

PS: I would think this would be a common enough thing to want to do that a ShowFocusRect="False" property on the grid view is worth considering.

15 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 17 Mar 2009, 12:39 PM
Hi Roger,

We definitely need such property!

Here is possible solution using RowLoaded event and our new extension methods:

private void RadGrid1_RowLoaded(object sender, RowLoadedEventArgs e)
{
   if (e.Row is GridViewRow)
   {
      e.Row.ChildrenOfType<Rectangle>().Where(r => r.Name == "CurrentBorder").ToList().ForEach(r => r.Opacity = 0);
   }
}

Sincerely yours,
Vlad
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Roger
Top achievements
Rank 1
answered on 18 Mar 2009, 01:52 AM
Vlad,

Thanks for the quick reply. Works quite well. A property would be best, long term, but I can live with this.

2'nd question: Can I hide the splitter bar that's left behind when I set RowIndicatorVisibility="Collapsed" on the grid? It gets left dangling out there on the left side with no real purpose.

Roger
0
Accepted
Vlad
Telerik team
answered on 18 Mar 2009, 07:03 AM
Hello Roger,

Please set CanUserFreezeColumns to false and let me know about the result.

Regards,
Vlad
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Roger
Top achievements
Rank 1
answered on 19 Mar 2009, 01:29 AM
Vlad,

I would have bet money I had already tried setting CanUserFreezeColumns and it didn't work. But I would have lost that bet...works just like you would expect.

Do you have any samples that show how to use RowAppearance.AlternateRowStyle?

Thanks. Your support is 1'st class!
0
Accepted
Pavel Pavlov
Telerik team
answered on 20 Mar 2009, 11:11 AM
Hello Roger,

Here is a small piece of XAML, demonstrating how to set alternating row style.
    <Grid x:Name="LayoutRoot" Background="White">  
        <Grid.Resources> 
            <Style x:Key="alternateRowStyle" TargetType="telreik:GridViewRow" > 
                <Setter Property="Background" Value="Green" /> 
            </Style> 
        </Grid.Resources> 
        <telerik:RadGridView x:Name="RadGridView1" > 
            <telerik:RadGridView.RowAppearance> 
                <telerik:RowAppearanceSettings AlternateRowStyle="{StaticResource alternateRowStyle}"/>  
            </telerik:RadGridView.RowAppearance> 
        </telerik:RadGridView> 
    </Grid> 


Best wishes,
Pavel Pavlov
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Krlos
Top achievements
Rank 1
answered on 11 Aug 2009, 08:33 PM

Dont forget to Activate AlternateRowStyleBehavior! 
<gridView:RadGridView x:Name="RadGridView1" UseAlternateRowStyle="True" AlternateRowStyle="{StaticResource alternateRowStyle}"  />
Alternative Declaration

 

 

 

 

0
James
Top achievements
Rank 1
answered on 16 Sep 2009, 06:51 AM
Hi Vlad,

6 months on, is this still the recommended way to disable the focus visual cue around selected cells?

Cheers,

James.
0
Kalin Milanov
Telerik team
answered on 18 Sep 2009, 02:56 PM
Hi James,

At the moment this still is a valid option for disabling the focus rectangle of the cell. Of course you can always edit the template of the cell and change the Focused visual state or / and delete the focus visual entirely.

On the other hand we are currently revisiting the cell as a part of our efforts to boost grid's performance. While doing so we will consider implementing some control over the focus rectangle (something in the lines os FocusVisualStyle) though we are still not sure about the exact implementation.

I would like to thank you for the patience and I hope you will be happy with our solution for this issue.

Greetings,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kalin Milanov
Telerik team
answered on 18 Sep 2009, 02:58 PM
Hi James,

At the moment this still is a valid option for disabling the focus rectangle of the cell. Of course you can always edit the template of the cell and change the Focused visual state or / and delete the focus visual entirely.

On the other hand we are currently revisiting the cell as a part of our efforts to boost grid's performance. While doing so we will consider implementing some control over the focus rectangle (something in the lines os FocusVisualStyle) though we are still not sure about the exact implementation.

I would like to thank you for the patience and I hope you will be happy with our solution for this issue.

Greetings,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
James
Top achievements
Rank 1
answered on 19 Sep 2009, 03:34 AM
Thanks very much Kalin, I think editing the cell template sounds like the best option.
Cheers,
James.
0
Patrick
Top achievements
Rank 1
answered on 15 Feb 2011, 04:42 AM
private void RadGrid1_RowLoaded(object sender, RowLoadedEventArgs e)
{
   if (e.Row is GridViewRow)
   {
      e.Row.ChildrenOfType<Rectangle>().Where(r => r.Name == "CurrentBorder").ToList().ForEach(r => r.Opacity = 0);
   }
}

Does not work for me. The list returns no items. Can you please tell me why?
I can't believe there is NO property for turning the selected cell border off. What should be a two second fix has turned into hours of searching google for hacks and trawling through your god-awful mess of styling xaml.
0
Vanya Pavlova
Telerik team
answered on 15 Feb 2011, 10:47 AM
Hello James,

The recommended approach to remove the border of GridViewCell in its current state is shown in the following online help article "Override the Default RadGridView Styles-Remove the Border of the Current Cell".

Greetings,
Vanya Pavlova
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sayix
Top achievements
Rank 1
answered on 18 Apr 2011, 01:56 AM
Any way to accomplish disabling cell focusing with the latest Silverlight Gridview control???
0
Suraj
Top achievements
Rank 1
answered on 09 Mar 2012, 09:50 AM
Hello,
I have the same issue with cell selection.
I've tried the solution given by you but it shows me an error as follows:

Telerik.Windows.Controls.GridView.GridViewRowItem' does not contain a definition for 'ChildrenOfType' and no extension method 'ChildrenOfType' accepting a first argument of type 'Telerik.Windows.Controls.GridView.GridViewRowItem' could be found (are you missing a using directive or an assembly reference?.

Whats the problem?? 
0
Jeff
Top achievements
Rank 1
answered on 28 Dec 2012, 06:28 AM
@Suraj - Since nobody else has taken the time to help you out I figured I'd let you know that the issue your seeing is likely that you don't have the necessary namespace included which introduces the ChildrenOfType extension method along with others. I believe you will have to create a using statement at the top of your file to bring in the namespace Telerik.Windows.Controls if memory serves correct.

This is one of the biggest problems that I see with extension methods is lack of discoverability. It's also a shame that the WPF suite includes MVVM base class stuff in that same namespace which collides with stuff in our any many other peoples projects. The workaround that I've been doing is to call the static methods directly instead of using the extension method syntax. I wish the namespaces would just be planned a bit more selectively to avoid this issue though.
Tags
GridView
Asked by
Roger
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Roger
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Krlos
Top achievements
Rank 1
James
Top achievements
Rank 1
Kalin Milanov
Telerik team
Patrick
Top achievements
Rank 1
Vanya Pavlova
Telerik team
sayix
Top achievements
Rank 1
Suraj
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Share this question
or