Kurt Boyer
Top achievements
Rank 1
Kurt Boyer
asked on 15 Jul 2014, 05:45 PM
Is there any way to set the focus immediately to the Search Row (enabled via AllowSearchRow = true) when a user is shown a form? Additionally, is there a way to hide the "Match case" button on the Search Row?
7 Answers, 1 is accepted
0
Kurt Boyer
Top achievements
Rank 1
answered on 16 Jul 2014, 04:43 PM
I've found a way to hide the "Match case" button. You can do that by editing the theme applied to the GridView control. Specifically, I loaded the theme into Visual Style Builder and traversed to RadGridView >> RadGridViewElement >> GridTableElement >> GridSearchRowElement >> GridSearchCellElement >> RadToggleButtonElement. On that element, you can set the "Visibility" to hidden.
The question about being able to set focus to the search row text box still remains though. Any thoughts are appreciated.
The question about being able to set focus to the search row text box still remains though. Any thoughts are appreciated.
0
Accepted
Hello Kurt,
Thank you for writing.
I can confirm that modifying the theme is one way to hide the button. As an alternative, one can modify the same cell programmatically. For the purpose, one should derive from the GridSearchCellElement, override the CreateMatchCaseButton and in it, set the button's Visibility:
To put this cell in action the CreateCell event of RadGridView should be used:
To focus the text box when the grid is focused, you can use the GotFocus event of RadGridView as follows:
I hope that you find this information useful.
Regards,
Stefan
Telerik
Thank you for writing.
I can confirm that modifying the theme is one way to hide the button. As an alternative, one can modify the same cell programmatically. For the purpose, one should derive from the GridSearchCellElement, override the CreateMatchCaseButton and in it, set the button's Visibility:
class
MyGridSearchCellElement : GridSearchCellElement
{
public
MyGridSearchCellElement(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{
}
protected
override
RadToggleButtonElement CreateMatchCaseButton()
{
RadToggleButtonElement matchCaseButton =
base
.CreateMatchCaseButton();
matchCaseButton.Visibility = ElementVisibility.Collapsed;
return
matchCaseButton;
}
}
To put this cell in action the CreateCell event of RadGridView should be used:
void
radGridView1_CreateCell(
object
sender, GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridSearchCellElement))
{
e.CellType =
typeof
(MyGridSearchCellElement);
}
}
To focus the text box when the grid is focused, you can use the GotFocus event of RadGridView as follows:
void
radGridView1_GotFocus(
object
sender, EventArgs e)
{
GridSearchCellElement searchCell = radGridView1.TableElement.GetCellElement(radGridView1.MasterView.TableSearchRow,
null
)
as
GridSearchCellElement;
if
(searchCell !=
null
)
{
searchCell.SearchTextBox.Focus();
}
}
I hope that you find this information useful.
Regards,
Stefan
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Brendan
Top achievements
Rank 1
answered on 13 Nov 2017, 09:42 PM
Since the CreateMatchCaseButton code is obsolete in the current release per this warning:
- "Warning 'Protected Overridable Overloads Function CreateMatchCaseButton() As RadToggleButtonElement' is obsolete: 'This method is obsolete. Use CreateOptionsButton and/or CreateMatchCaseMenuItem methods instead.'
The following code can be used to hide the match case button;
'class to hide Match Case button on grid search row via CreateCell event
Class
MyGridSearchCellElement
Inherits
GridSearchCellElement
Public
Sub
New
(column
As
GridViewColumn, row
As
GridRowElement)
MyBase
.
New
(column, row)
End
Sub
Protected
Overrides
Function
CreateOptionsButton()
As
RadDropDownButtonElement
Dim
matchCaseButton
As
RadDropDownButtonElement =
MyBase
.CreateOptionsButton()
matchCaseButton.Visibility = ElementVisibility.Collapsed
Return
matchCaseButton
End
Function
End
Class
Private
Sub
grdMyGrid_CreateCell(sender
As
Object
, e
As
GridViewCreateCellEventArgs)
Handles
grdMyGrid.CreateCell
'finds search cell element and hides Match Case button
On
Error
Resume
Next
If
e.CellType =
GetType
(GridSearchCellElement)
Then
e.CellType =
GetType
(MyGridSearchCellElement)
e.Row.RowInfo.MinHeight = 30
End
If
End
Sub
0
Hi Brendan,
Thank you for writing in the thread.
Indeed the CreateMatchCaseButton method is obsolete as of R1 2017 so for any later versions of the controls and in the context of the discussed scenario one should use the new CreateOptionsButton method.
I hope this helps.
Regards,
Hristo
Progress Telerik
Thank you for writing in the thread.
Indeed the CreateMatchCaseButton method is obsolete as of R1 2017 so for any later versions of the controls and in the context of the discussed scenario one should use the new CreateOptionsButton method.
I hope this helps.
Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brendan
Top achievements
Rank 1
answered on 06 Jul 2018, 06:56 PM
Hi Hristo, when I load the grid I can hide the CreateOptionsbutton (Telerik version 2017.3.912.40) via the CreateCell event.
However, I have a checkbox column in the grid and notice when I click the checkbox, the options button becomes visible again. Do you know why this happens? Is there a way to identify the button after the grid has been created and make it invisible again?
Thanks.
0
Hello Brendan,
With the version of the controls after R1 2017, there is a separate drop-down button in which the match-case item is located. It is still initialized in a virtual Create method which you can override in the custom search cell element. I have also tested the scenario with the checkbox column the Visibility of the menu item did not change:
I am also attaching a short video showing the result on my end.
Yet if the visibility property changes at some point during the execution of your application, you can also handle its RadPropertyChanging event and cancel it this way:
Regards,
Hristo
Progress Telerik
With the version of the controls after R1 2017, there is a separate drop-down button in which the match-case item is located. It is still initialized in a virtual Create method which you can override in the custom search cell element. I have also tested the scenario with the checkbox column the Visibility of the menu item did not change:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
this
.radGridView1.CreateCell += RadGridView1_CreateCell;
this
.radGridView1.DataSource =
this
.GetData();
this
.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.AllowSearchRow =
true
;
((GridViewCheckBoxColumn)
this
.radGridView1.Columns[
"Bool"
]).EnableHeaderCheckBox =
true
;
}
private
void
RadGridView1_CreateCell(
object
sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridSearchCellElement))
{
e.CellType =
typeof
(MyGridSearchCellElement);
}
}
private
DataTable GetData()
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(
int
));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"Date"
,
typeof
(DateTime));
dt.Columns.Add(
"Bool"
,
typeof
(
bool
));
dt.Columns.Add(
"Description"
,
typeof
(
string
));
for
(
int
i = 0; i < 100; i++)
{
dt.Rows.Add(i,
"Name "
+ i, DateTime.Now.AddDays(i), i % 2 == 0,
"Description "
+ i);
}
return
dt;
}
}
class
MyGridSearchCellElement : GridSearchCellElement
{
public
MyGridSearchCellElement(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{ }
protected
override
RadMenuItem CreateMatchCaseMenuItem()
{
RadMenuItem result =
base
.CreateMatchCaseMenuItem();
result.Visibility = ElementVisibility.Collapsed;
return
result;
}
}
I am also attaching a short video showing the result on my end.
Yet if the visibility property changes at some point during the execution of your application, you can also handle its RadPropertyChanging event and cancel it this way:
class
MyGridSearchCellElement : GridSearchCellElement
{
public
MyGridSearchCellElement(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{ }
protected
override
RadMenuItem CreateMatchCaseMenuItem()
{
RadMenuItem result =
base
.CreateMatchCaseMenuItem();
result.Visibility = ElementVisibility.Collapsed;
result.RadPropertyChanging += Result_RadPropertyChanging;
return
result;
}
private
void
Result_RadPropertyChanging(
object
sender, RadPropertyChangingEventArgs args)
{
if
(args.Property == LightVisualElement.VisibilityProperty && (ElementVisibility)args.NewValue == ElementVisibility.Visible)
{
args.Cancel =
true
;
}
}
}
Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brendan
Top achievements
Rank 1
answered on 09 Jul 2018, 03:16 PM
Thanks Hristo, that worked perfectly