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

[Solved] Remove Focus rectangle in ReadOnly grid

2 Answers 289 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anne Lyon
Top achievements
Rank 1
Anne Lyon asked on 20 Jul 2011, 01:27 PM
Hi,

I would like to remove the currentItem focus rectangle from my grid as it is read only and giving a cell the focus doesn't really make sense and makes the grid look "cluttered".
I have tried a solution I found in the forum with adding a "RowLoaded" callback to the grid and inserting the code:
if (e.Row is GridViewRow)
{
    e.Row.ChildrenOfType<Rectangle>().Where(r => r.Name == "CurrentBorder").ToList().ForEach(r => r.Opacity = 0);
}

But this callback has no effect on my Focus rectangle.
Anything else I can try?

2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Zagorski
Telerik team
answered on 21 Jul 2011, 09:34 AM
Hello Anne Lyon,

You could try to edit the GridViewCell template and remove the Background_Current border and its visual state as illustrated in our online documentation here.

Another way is to handle the CurrentCellChanged event of the grid and execute the following code:
private void RadGridView_CurrentCellChanged(object sender, Telerik.Windows.Controls.GridViewCurrentCellChangedEventArgs e)
        {
            if (e.OldCell != null)
            {
                var Border = e.NewCell.ChildrenOfType<Border>().Where(r => r.Name == "Background_Current").FirstOrDefault();
                Border.Opacity = 0;
            }
Vladimir Zagorski

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Anne Lyon
Top achievements
Rank 1
answered on 21 Jul 2011, 10:23 AM
Thanks Vladimir,

The CurrentCellChanged callback is fired only when I click on a row, but I wanted the focus to be gone as the table is loaded. But I found that I could use my original callback for RowLoaded but adding your code instead:
private void DokKrav_RowLoaded(object sender, RowLoadedEventArgs e)
 {
     if (e.Row is GridViewRow)
     {
          var Border = e.Row.ChildrenOfType<Border>().Where(r => r.Name == "Background_Current").FirstOrDefault();
         Border.Opacity = 0;
     }
 }
Everything is working fine now!
Anne
Tags
GridView
Asked by
Anne Lyon
Top achievements
Rank 1
Answers by
Vladimir Zagorski
Telerik team
Anne Lyon
Top achievements
Rank 1
Share this question
or