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

Which Event to raise while typing on GridViewComboBoxColumn of Terlik Radgridview in WinForms

15 Answers 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
rajasekar
Top achievements
Rank 1
rajasekar asked on 12 Apr 2018, 01:46 PM

I have a Terlik Radgridview with GridViewComboBoxColumn and GridViewTextBoxColumns,In that I want to raise a event while typing on GridViewTextBoxColumn

15 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 13 Apr 2018, 08:23 AM
Hi Rajasekar,

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
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
rajasekar
Top achievements
Rank 1
answered on 13 Apr 2018, 08:54 AM

Thank you Dimitar, This was so helpfull.

I need the same for GridViewComboBoxColumn  instead of GridViewTextBoxColumn

 

0
Accepted
Dimitar
Telerik team
answered on 13 Apr 2018, 10:58 AM
Hello Rajasekar,

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.
 
Regards,
Dimitar
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
rajasekar
Top achievements
Rank 1
answered on 16 Apr 2018, 06:39 AM

Hi Dimitar,

Thank you show much, Its working fine....

How we get value of typed text in TextBoxItem_KeyPress event

 

0
Accepted
Dimitar
Telerik team
answered on 16 Apr 2018, 08:17 AM
Hello Rajasekar,

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.
 
Regards,
Dimitar
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
rajasekar
Top achievements
Rank 1
answered on 16 Apr 2018, 09:53 AM

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.

0
rajasekar
Top achievements
Rank 1
answered on 16 Apr 2018, 10:02 AM

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...

0
Dimitar
Telerik team
answered on 17 Apr 2018, 08:00 AM
Hello Rajasekar,

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
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
rajasekar
Top achievements
Rank 1
answered on 17 Apr 2018, 09:40 AM

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

 

 

0
Accepted
Dimitar
Telerik team
answered on 17 Apr 2018, 10:20 AM
Hi Rajasekar,

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
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
rajasekar
Top achievements
Rank 1
answered on 17 Apr 2018, 11:25 AM

Thank you so much Dimitar, now its working fine.I have done my work...

0
Shahid
Top achievements
Rank 1
answered on 06 Jun 2019, 07:37 AM
Tab key is not working in TextBoxItem_KeyDown event for DropDown.
0
Dimitar
Telerik team
answered on 06 Jun 2019, 10:39 AM
Hi Shahid,

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.
 
Regards,
Dimitar
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.
0
Shahid
Top achievements
Rank 1
answered on 07 Jun 2019, 06:26 AM

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?

0
Dimitar
Telerik team
answered on 07 Jun 2019, 12:46 PM
Hi Shahid,

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
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
rajasekar
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
rajasekar
Top achievements
Rank 1
Shahid
Top achievements
Rank 1
Share this question
or