Hello,
I'm using the very good built in serch function AllowSearchRow.
However I have it hidden by default and made it possible to use via a menu and a RadShortcut.
When the user clicks the menu (button in my sample below) I would like the SearchRow to show and put focus to the searchbox textbox. But the searchCell is null when the SearchRow is shown.
I suppose I need to put the AllowSearchRow = true and the searchCell.SearchTextBox.Focus() in two different Events, but which ones?
Any suggestions appretiated!
My sample:
using
System;
using
System.Collections.Generic;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
namespace
SearchTextBoxFocus
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
List<MyObject> myList =
new
List<MyObject>();
myList.Add(
new
MyObject(1,
"Outdoor"
));
myList.Add(
new
MyObject(2,
"Hardware"
));
myList.Add(
new
MyObject(3,
"Tools"
));
myList.Add(
new
MyObject(4,
"Books"
));
myList.Add(
new
MyObject(5,
"Appliances"
));
radGridView1.DataSource = myList;
}
private
void
button1_Click(
object
sender, EventArgs e)
{
this
.radGridView1.AllowSearchRow = !
this
.radGridView1.AllowSearchRow;
GridSearchCellElement searchCell = radGridView1.TableElement.GetCellElement(radGridView1.MasterView.TableSearchRow,
null
)
as
GridSearchCellElement;
if
(searchCell !=
null
)
{
searchCell.SearchTextBox.Focus();
}
}
}
}
public
class
MyObject
{
public
MyObject(
int
myInt,
string
myString)
{
_myInt = myInt;
_myString = myString;
}
private
int
_myInt;
public
int
MyInt
{
get
{
return
_myInt; }
set
{ _myInt = value; }
}
private
string
_myString;
public
string
MyString
{
get
{
return
_myString; }
set
{ _myString = value; }
}
}