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

FilterRow Focus

8 Answers 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 06 Nov 2012, 11:26 AM
Hello!

One simple question: How can I set the focus to the FilterRow within a RadGridView?
Thanks a lot!!!
Tim.

8 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 06 Nov 2012, 12:23 PM
Hello,

Here is one possible approach to do this:

public MainWindow()
{
    InitializeComponent();
 
    this.clubsGrid.Loaded += new RoutedEventHandler(clubsGrid_Loaded);
}
 
void clubsGrid_Loaded(object sender, RoutedEventArgs e)
{
    var grid = ((RadGridView)sender);
 
    var firstHeaderCell = grid.ChildrenOfType<GridViewHeaderCell>()
        .SingleOrDefault(headerCell => headerCell.Column == grid.Columns["Name"]);
         
    var firstFilterControl = firstHeaderCell.ChildrenOfType<FieldFilterControl>().FirstOrDefault();
    if (firstFilterControl != null)
    {
        // You may want to change this if the first column shows a RadDateTimePicker instead of StringFilterEditor.
        var textBox = firstFilterControl.ChildrenOfType<TextBox>().FirstOrDefault();
        if (textBox != null)
        {
            textBox.Focus();
        }
    }
}

I have attached a sample project which you can tweak to suit your needs.

All the best,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tim
Top achievements
Rank 1
answered on 06 Nov 2012, 01:50 PM
Hi Rossen, thanks a lot for the fast reply! I'll try it...
0
Tim
Top achievements
Rank 1
answered on 06 Nov 2012, 02:41 PM

Hello. Unfortunately with Silverlight and

var firstHeaderCell = grid.ChildrenOfType<GridViewHeaderCell>().SingleOrDefault(headerCell => headerCell.Column == grid.Columns["Label"]);

firstHeaderCell is always null! My column definition looks something like:

<telerik:GridViewDataColumn UniqueName="Label" Header="Labels:" Width="*">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <telerik:RadButton HorizontalContentAlignment="Left">
                <TextBlock Text="{Binding Label}" />
            </telerik:RadButton>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate
</telerik:GridViewDataColumn>

I tried it with different LINQ queries but all I get are exceptions... ;) Any ideas?
Thanks a lot,
Tim.




0
Rossen Hristov
Telerik team
answered on 06 Nov 2012, 02:45 PM
Hello,

1. Can you try on a different event such as DataLoaded?

2. Does grid.ChildrenOfType<GridViewHeaderCell>() return any header cells at all?

Kind regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tim
Top achievements
Rank 1
answered on 06 Nov 2012, 05:05 PM
Hi Rossen,

the code is working for some events, for example FilterOperatorsLoading, but the focus will not be set anyway - perhaps because the control is not yet being displayed? It works "perfectly" with the MouseMove event - but of course nobody want to do that!!! Unfortunately I didn't found an event that suits my needs! Ideas? Thanks a lot!!!

Tim.
0
Accepted
Rossen Hristov
Telerik team
answered on 07 Nov 2012, 09:23 AM
Hello,

Silverlight is a tricky platform regarding the focus. Here is what I invented:

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
 
        this.clubsGrid.LayoutUpdated += clubsGrid_LayoutUpdated;
    }
 
    void clubsGrid_LayoutUpdated(object sender, EventArgs e)
    {
        if (firstEditor != null)
        {
            System.Windows.Browser.HtmlPage.Plugin.Focus();
             
            firstEditor.ChildrenOfType<TextBox>().Single().Focus();
             
            this.clubsGrid.LayoutUpdated -= clubsGrid_LayoutUpdated;
        }
    }
 
    private FrameworkElement firstEditor;
     
    private void clubsGrid_FieldFilterEditorCreated_1(object sender, Telerik.Windows.Controls.GridView.EditorCreatedEventArgs e)
    {
        if(e.Column == this.clubsGrid.Columns["Name"])
        {
            this.firstEditor = e.Editor;
        }
    }

You can find a working project attached.

Greetings,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tim
Top achievements
Rank 1
answered on 07 Nov 2012, 10:29 AM
Hi Rossen,

thank you so much for your help!!! And I have to say: That did the trick!!! Well, not to 100%; I ended up with something like:
TextBox tb = this._firstEditor.ChildrenOfType<TextBox>().Single();
            tb.GotFocus -= this.TbGotFocus;
            tb.GotFocus += this.TbGotFocus;
            tb.Focus();
        }
 
        void TbGotFocus(object sender, RoutedEventArgs e)
        {
            this.RadGridView1.LayoutUpdated -= RadGridView1LayoutUpdated;
        }

Only with this change I can be 100% sure that the focus is set!
Thanks a lot, Rossen!!!
Tim.

0
Rossen Hristov
Telerik team
answered on 07 Nov 2012, 11:05 AM
Hello,

Just have in mind that if your column is DateTime this will be a RadDateTimePicker instead of a TextBox.

Boolean columns are also different.

Greetings,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Tim
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Tim
Top achievements
Rank 1
Share this question
or