How to remove focus rectangle from selected cell

16 posts, 0 answers
  1. Geoff Hardy
    Geoff Hardy avatar
    58 posts
    Member since:
    Feb 2010

    Posted 03 Aug 2010 Link to this post

    I recently upgraded from the 2010 Q1 controls to the 2010 Q2 controls. One change to the RadGridView that I have noticed is that when you click on a cell, a black rectangle is drawn around the cell to indicate that the cell has focus.

    This is good in many cases, except for some grids which are read-only. In this case, I just want to select the entire row but not set focus on the cell that was clicked. In other words, I do not want the black focus rectangle to show up at all. I have SelectionMode="Single" and SelectionUnit="FullRow", but this does not appear to have any effect on whether or not the focus rectangle shows up.

    Is there an easy way to turn off this focus rectangle?
  2. Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 04 Aug 2010 Link to this post

    Hi Geoff Hardy,

    To do that you will need to edit the template of the cell and change the focus visual state to handle this case. 
    Attached I am sending you a sample to get you started. 

    Best wishes,
    Kalin Milanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Geoff Hardy
    Geoff Hardy avatar
    58 posts
    Member since:
    Feb 2010

    Posted 04 Aug 2010 Link to this post

    Thanks Kalin. This solution does indeed work.

    Is this this simplest way to achieve this? Any time I have to add 200 lines of xaml to do something that seems like it should be a line line change, I start to wonder if there is an easier way. Adding all that extra xaml seems somewhat convoluted and I am not sure that there is any guarantee that it will all work OK in future versions of the RadGridView. Also, I don't really understand what was changed in the control template.

    I thought maybe there would be a way to do it by defining a SolidColorBrush resource with the right name, that the grid would use when drawing the focus rectangle around the current cell?
  5. Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 05 Aug 2010 Link to this post

    Hello Geoff Hardy,

    More often than not we are facing the "Chicken or the Egg" problem. The case with marking the current cell is no different. We went through many iterations on this how to present the visual for the current cell in an unobtrusive way. What you see is the result of a great deal of customer feedback collected for over a year ultimately leading us to believe that we would rather have it visible as it is easier to remove it than create it from scratch.

    On the matter of simplicity - actually this is the simplest way to achieve this. You can also do it in code, but the logic of it would be far more complex (with less lines true) than this. On a side note this is the natural way of restyling controls and 200 lines of XAML look scarier than they actually are. 

    As for what was changed - there is a Current visual state which by default contains an animation setting the visibility of the Background_Current border to visible. I have just removed that animation to get the desired result.

    Any feedback on this is greatly appreciated as we are always looking into ways of improving our controls.

    All the best,
    Kalin Milanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. bruno
    bruno avatar
    15 posts
    Member since:
    Sep 2010

    Posted 09 Sep 2010 Link to this post

    I have the same problem.

    I can't open that project, because i am using visual studio 2008.
    What i have to do to apply that XAML in my project?
  7. bruno
    bruno avatar
    15 posts
    Member since:
    Sep 2010

    Posted 10 Sep 2010 Link to this post

    Ups... my problem is in Windows Form. Only now i noticed  that this is in Silverlight.
  8. bruno
    bruno avatar
    15 posts
    Member since:
    Sep 2010

    Posted 10 Sep 2010 Link to this post

    I solved my problem doing this:

    ...
    radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
    ...


    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
          e.CellElement.DrawBorder = false;
    }
  9. Aaron
    Aaron avatar
    19 posts
    Member since:
    Dec 2010

    Posted 07 Dec 2010 Link to this post

    I would like to second Geoff's frustration with the fact that this property is not exposed without having to 'override' (probably not the best way to call it) the control's properties. One issue I see with this is that once you edit the template, all the properties are now hardcoded so any upgrades to the control will need manual updates to the template. In my situation my project's gridview is readonly so for me it's just an annoyance the fact that it highlights the cell since it serves no purpose.
    Aaron
  10. Odin
    Odin avatar
    1 posts
    Member since:
    Jan 2011

    Posted 12 Jan 2011 Link to this post

    Kalin,

    you wrote " you will need to edit the template of the cell and change the focus visual state"...sorry but I did not find visual state Focus in the code. It is still a mystery to me how it works.

    Thank you,
       odin...
  11. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 13 Jan 2011 Link to this post

    Hello Geoff,

    Focus VisualStyle property is related to WPF. You will find an example in our online documentation how to remove focus visual style, following this link:
    http://www.telerik.com/help/wpf/how-to-override-default-gridview-styles.html

    On the other hand if you are using RadGridView/Silverlight, follow this link:
    http://www.telerik.com/help/silverlight/how-to-override-default-gridview-styles.html


    All the best,
    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>>
  12. Guillermo
    Guillermo avatar
    4 posts
    Member since:
    Aug 2012

    Posted 07 Sep 2012 Link to this post

    Hi, in the last version Q1 2012 SP1 how cant i acomplish remove focus rectangle from cell ?
    I am using the Vista theme

  13. LM IT
    LM IT avatar
    9 posts
    Member since:
    Feb 2014

    Posted 04 Nov 2014 in reply to Aaron Link to this post

    I'm joining in with the frustration.

    Cell highlighting should be optionally able to disable, I've used the gridview in lots of projects and so far I've never needed the Cell focus border as I almost always use the grid with readonly view and FullRow selection so it just confuses the end users. Is there an easier workaround in the latest releases? I'd rather not override the whole style, because as Aaron mentioned it is a nuisance when upgrading to newer versions.
  14. Timothy
    Timothy avatar
    5 posts
    Member since:
    May 2013

    Posted 06 Jul 2015 Link to this post

    I am going to second has already been said above.
  15. Leonid
    Leonid avatar
    2 posts
    Member since:
    Feb 2012

    Posted 07 Jul 2015 Link to this post

    Hello,

     Is there a better solution for removing the cell border without editing the GridViewCell style? 

  16. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Jul 2015 Link to this post

    Hi,

    You can control the visibility of all grid lines through configuring RadGridView's GridLinesVisibility property.

    Otherwise, as to removing the current border/focus rectangle, I am afraid there is not a setting to suggest.
    You can either Edit the Control Template as explained in the article or directly modify the specific template in Themes/Telerik.Windows.Controls.GridView.xaml file. The second approach is illustrated in Setting a Theme (Using Implicit Styles).  

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  17. Tim
    Tim avatar
    18 posts
    Member since:
    Jul 2013

    Posted 26 Jan in reply to Dimitrina Link to this post

    I created a feedback item about this issue. You might want to vote.
Back to Top
DevCraft banner