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

Focus on a specific filter on a grid

9 Answers 409 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Loïc
Top achievements
Rank 1
Loïc asked on 21 Jun 2017, 08:49 AM

Hello,

I want to focus specific filter in a radgridview. I tried beginEdit event but i don't want to select text, just focus.

GridView.MasterGridViewInfo.TableFilteringRow.Cells[index].BeginEdit();

 

Focus() on the CellElement doesn't work.

How i can do that ?

9 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Jun 2017, 09:37 AM
Hello Loïc, 

Thank you for writing.  

Calling the BeginEdit method will activate the editor for the respective cell. Note that the filter row doesn't indicate selection as the data rows. You can make the filter row current by setting the RadGridView.CurrentRow property to MasterView.TableFilteringRow and change the CurrentColumn. Then, you can use the ViewCellFormatting event in order to customize the style for the selected cell and thus indicate which is the current filter cell. Here is a sample code snippet:
public RadForm1()
{
    InitializeComponent();
 
    this.radGridView1.EnableFiltering = true;
    this.radGridView1.CurrentRow = this.radGridView1.MasterView.TableFilteringRow;
    this.radGridView1.CurrentColumn = this.radGridView1.Columns["UnitPrice"];
}
private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement == this.radGridView1.CurrentCell)
    {
        e.CellElement.BorderColor = Color.DarkOrange;
        e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder;
        e.CellElement.BorderWidth = 2;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderWidthProperty, ValueResetFlags.Local);
    }
}

If it is not the exact requirement please specify in details what is the exact goal that you are trying to achieve. Thus, we would be able to think about a suitable solution.

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abba
Top achievements
Rank 1
answered on 03 Aug 2017, 06:23 AM
Once again, this and other solutions do NOT work to fit the need!
Here are 2 other threads suggesting something similar yet different code (NONE work as needed!!)
http://www.telerik.com/forums/gridview-filter-row-focus-not-showing-cursor-and-textbox-programmatically
http://www.telerik.com/forums/focus-a-filter-box-by-program

GO check the original post screenshot.  It CLEARLY shows the cursor in the filter textbox.  Thus allowing the user to just type and it will filter.
Your proposed solution contradicts the other threads and also does not produce the correct results.

AGAIN, this is BASIC and should be SO simple.  I wasted almost an hour having to try different ways back and forth.  The only thing i could do is to have it so when i type it filters.  But the textbox doesn't show until i start typing.  NOT like the screenshot (which is also what i want).  Why is this so hard?!?!

HOW DO YOU GET IT TO WORK EXACTLY AS PICTURED? --> Programmatically set the filter to show with the cursor in the texbox!

...More half-way compromise solutions because of an half-way to beta product.
0
Loïc
Top achievements
Rank 1
answered on 03 Aug 2017, 06:48 AM

I found another solution to work around the problem (for info the project runs on Telerik 2010) :

CurrentGrid.CurrentRow = CurrentGrid.MasterGridViewInfo.TableFilteringRow;
CurrentGrid.CurrentColumn = CurrentGrid.Columns[indexFocusFilter.Value];
CurrentGrid.BeginEdit();
RadTextBoxEditor textBoxEditor = (RadTextBoxEditor)CurrentGrid.CurrentCell.Editor;
RadTextBoxEditorElement textBoxItem = ((RadTextBoxEditorElement)textBoxEditor.EditorElement);
 
textBoxItem.SelectionStart = textBoxEditor.Value.ToString().Length;
textBoxItem.SelectionLength = 0;

 

Hope this helps you.

 

0
Abba
Top achievements
Rank 1
answered on 04 Aug 2017, 03:36 AM

Hi Loic,

Thank you for following up and providing your solution.
Unfortunately this doesn't seem to work for me because textBoxItem (RadTextBoxEditorElement) does not have a SelectionStart or SelectionLength properties.

I am on telerik 2013.

0
Loïc
Top achievements
Rank 1
answered on 04 Aug 2017, 06:48 AM

Hi Abba,

On recent Telerik's version i think this work :

RadTextBoxEditor textBox = (RadTextBoxEditor)this.GridViewElement.ActiveEditor;
                       RadTextBoxItem textBoxItem = ((RadTextBoxElement)textBox.EditorElement).TextBoxItem;
                       textBoxItem.SelectionStart = this.GridViewElement.ActiveEditor.Value.ToString().Length;
                       textBoxItem.SelectionLength = 0;
0
Abba
Top achievements
Rank 1
answered on 05 Aug 2017, 02:11 AM

Hi Loic,

I really appreciate your help.  

With your code, the texbox now has the properties, but when I run the app it still doesn't have the cursor in the textbox.
I'm not sure why. It seems like it should. :(

Thank you so much for the effort though.  That is very kind of you.

0
Abba
Top achievements
Rank 1
answered on 05 Aug 2017, 02:38 AM

By the way, I have a feeling that it maybe because of some other property/setting of the grid that makes this not work.
Typical of telerik controls, where something only works with the original default basic grid.  If you try to change/customize more than one thing they don't work.  Each only works separate.  So users have to compromise to only be able to get one feature.  Sad.  Like I have said before, these controls are built on sand.  And they don't  care to fix/change.

I can't waste more and more time trying to track down their bugs and why my grid this doesn't work as it should.  More time is spent fighting their controls then any other development.  I have to move on until I can change them out.

0
Nicola
Top achievements
Rank 1
answered on 15 Oct 2019, 04:42 PM

In FilterPopupInitialized of RadGridView add:

 AddHandler Item_RadListFilterPopup.PopupOpened, AddressOf FilterPopUpOpened

In FilterPopUpOpened add:

 For Each item As RadItem In Item_RadListFilterPopup.Items
            If TypeOf item Is FilterMenuTextBoxItem Then
                If item.Visibility = ElementVisibility.Visible Then
                    AddHandler TryCast(item, FilterMenuTextBoxItem).TextBox.Paint, AddressOf FilterPopupTextPaint
                    Exit For
                End If
            End If
        Next

in FilterPopupTextPaint Event add:

        Dim Item_FilterMenuTextBoxItem As RadTextBox = TryCast(sender, RadTextBox)
        If Item_FilterMenuTextBoxItem Is Nothing Then Return

        RemoveHandler Item_FilterMenuTextBoxItem.Paint, AddressOf FilterPopupTextPaint

        Item_FilterMenuTextBoxItem.Focus()

 

--------------------

 

This workaround work good.

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Oct 2019, 12:37 PM
Hello, Nicola,      

According to the provided information, it seems that you use Excel-like filtering, not the basic filtering. The FilterPopupInitialized event is expected to be fired when the Excel-like filter popup is shown. I suppose that you are trying to focus the text-box above the tree-view with the distinct values. Please refer to the following code snippet which offers an alternative solution to the Paint event of the text box to focus it:
        public RadForm1()
        {
            InitializeComponent();

            this.radGridView1.ShowHeaderCellButtons = true;
            this.radGridView1.EnableFiltering = true; 

            this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized;
        }

        private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
        {
            ((RadListFilterPopup)e.FilterPopup).PopupOpened += RadForm1_PopupOpened;
        }

        private void RadForm1_PopupOpened(object sender, EventArgs args)
        {
            RadListFilterPopup popup = sender as RadListFilterPopup;
            popup.TextBoxMenuItem.TextBox.TextBoxElement.TextBoxItem.TextBoxControl.LostFocus -= TextBoxControl_LostFocus;
            popup.TextBoxMenuItem.TextBox.TextBoxElement.TextBoxItem.TextBoxControl.LostFocus += TextBoxControl_LostFocus;
            popup.TextBoxMenuItem.TextBox.TextBoxElement.TextBoxItem.HostedControl.Focus();
        }
        
        private void TextBoxControl_LostFocus(object sender, EventArgs e)
        {
            TextBox tb = sender as TextBox;
            tb.Focus();
            tb.LostFocus -= TextBoxControl_LostFocus;
        }
Feel free to use this approach which suits your requirement best.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Loïc
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Abba
Top achievements
Rank 1
Loïc
Top achievements
Rank 1
Nicola
Top achievements
Rank 1
Share this question
or