15 Answers, 1 is accepted
You should use the editor events. Here is an example:
private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
if (e.Column.Name == "Name")
{
var editor = e.ActiveEditor as RadTextBoxEditor;
var element = editor.EditorElement as RadTextBoxEditorElement;
element.TextBoxItem.KeyDown -= TextBoxItem_KeyDown;
element.TextBoxItem.KeyPress -= TextBoxItem_KeyPress;
element.TextBoxItem.KeyDown += TextBoxItem_KeyDown;
element.TextBoxItem.KeyPress += TextBoxItem_KeyPress;
}
}
private void TextBoxItem_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void TextBoxItem_KeyDown(object sender, KeyEventArgs e)
{
}
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
Thank you Dimitar, This was so helpfull.
I need the same for GridViewComboBoxColumn instead of GridViewTextBoxColumn
Here is the code for GridViewComboBoxColumn:
private
void
RadGridView1_CellEditorInitialized(
object
sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if
(e.ActiveEditor
is
RadDropDownListEditor)
{
RadDropDownListEditor editor = e.ActiveEditor
as
RadDropDownListEditor;
RadDropDownListEditorElement element = editor.EditorElement
as
RadDropDownListEditorElement;
element.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
element.TextBox.TextBoxItem.KeyDown += TextBoxItem_KeyDown;
element.TextBox.TextBoxItem.KeyDown += TextBoxItem_KeyDown;
}
}
private
void
TextBoxItem_KeyDown(
object
sender, KeyEventArgs e)
{
}
Do not hesitate to contact us if you have other questions.
Dimitar
Progress Telerik
Hi Dimitar,
Thank you show much, Its working fine....
How we get value of typed text in TextBoxItem_KeyPress event
Here is the code for getting the text:
private
void
TextBoxItem_KeyDown(
object
sender, KeyEventArgs e)
{
var textBoxItem = sender
as
RadTextBoxItem;
var text = textBoxItem.Text;
}
Let me know if I can assist you further.
Dimitar
Progress Telerik
Hi Dimitar,
Now I am getting value of my typed text..
I wanna search name in my db by using that typed text and bind in same column(GridViewComboBoxColumn)
I am trying like this
private void TextBoxItem_KeyDown(object sender, KeyEventArgs e)
{
var textBoxItem = sender as RadTextBoxItem;
var text = textBoxItem.Text;
Datatable dt = new DataTable();
string sql = "select firstname from Namemaster where firstname like '%" + text + "%' or lastname like '%" + text + "%' or middlename like '%" + text + "%'";
dt = objdl.getDataTable(sql);
GridViewComboBoxColumn comboboxcolumn = (radGV.Columns["Combo"] as GridViewComboBoxColumn);
comboboxcolumn.DataSource = dt;
}
public DataTable getDataTable(string str)
{
con.Open();
sqlcom = new SqlCommand(str, con);
sqlcom.CommandTimeout = 300;
dr = sqlcom.ExecuteReader();
dt = new DataTable();
dt.Load(dr);
con.Close();
}
But it will not working properly
I want to display firstname only in my GridViewComboBoxColumn if i searching with lastname and middlename.
while searching with firstname everything is fine, i need the same result for lastname and middlename.
Actually me need is..
I hava RadGridView with GridViewComboBoxColumn with AutoComplete, while i am searching in GridViewComboBoxColumn i want to check in my table with firstname,lastname and midlename with typed text and bind firstname only in my GridViewComboBoxColumn
I need a solution for this...
This can be achieved by using GridViewMultiComboBoxColumn and setting the AutoFilter functionality to use composite filter: Filtering | RadMultiColumnComboBox.
You can use the same approach from the previous posts and access the editor in the CellEditorInitialized event handler and set its properties there.
I hope this will be useful.
Regards,
Dimitar
Progress Telerik
Hi Dimitar,
I have RadGridview with GridViewTextBoxColumn and I have some value in my GridViewTextBoxColumn then i want to assign again value in GridViewTextBoxColumn
my code is
radGV.Rows[radGV.CurrentCell.RowIndex].Cells["Colname"].Value = "aaaaa";
But its throw exception
Object reference not set to an instance of object
You need to check if the CurrentCell is null, and it would be better to set the value without using indexes. Here is an example:
if
(radGridView1.CurrentRow !=
null
)
{
radGridView1.CurrentRow.Cells[
"Name"
].Value =
"Test"
;
}
I hope this will be useful.
Regards,
Dimitar
Progress Telerik
Thank you so much Dimitar, now its working fine.I have done my work...
The Tab key is handled by the grid and it is not forwarded to the text box. To handle the Tab key you need a custom GridDataRowBehavior. Here is an example:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
BaseGridBehavior gridBehavior = radGridView1.GridBehavior
as
BaseGridBehavior;
gridBehavior.UnregisterBehavior(
typeof
(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(
typeof
(GridViewDataRowInfo),
new
CustomGridRowBehavior());
}
}
class
CustomGridRowBehavior : GridDataRowBehavior
{
protected
override
bool
ProcessTabKey(KeyEventArgs keys)
{
//add your logic here
return
base
.ProcessTabKey(keys);
}
}
I hope this helps. Should you have any other questions, do not hesitate to ask.
Dimitar
Progress Telerik
Thanks Dimitar for the reply.
Actually i have a grid having GridViewComboBoxColumn Column. Below is the code how i added combo box column.
GridViewComboBoxColumn cmbProducts =
new
GridViewComboBoxColumn();
cmbProducts.DataSource = ClsProducts.GetActiveProducts();
cmbProducts.DisplayMember =
"ProductName"
;
cmbProducts.ValueMember =
"ProductID"
;
cmbProducts.Width = 280;
cmbProducts.HeaderText =
"Product"
;
cmbProducts.Name =
"ColProduct"
;
cmbProducts.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
cmbProducts.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
dgvTrade.Columns.Insert(0, cmbProducts);
Now when i filter product in the combo box e.g i filter product "Keyboard" by typing "Key" and Keyboard is selected, but if i press the "Enter" key then product is actually selected and if i press "Tab" key the filtered product disappear. Is it possible that i press "Tab" key and get functionality of "Enter" key?
I have tested this and it works fine on my side (see attached). Am I testing wrong? Which version of the suite are you using?
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik