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
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
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.
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.
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.
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;
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.
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.
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.
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;
}
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik