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

16 posts, 4 answers
  1. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 12 Apr 2018 Link to this post


    I have a Terlik Radgridview with GridViewComboBoxColumn and GridViewTextBoxColumns,In that I want to raise a event while typing on GridViewTextBoxColumn
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 13 Apr 2018 Link to this post

    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.
  3. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 13 Apr 2018 in reply to Dimitar Link to this post

    Thank you Dimitar, This was so helpfull.

    I need the same for GridViewComboBoxColumn  instead of GridViewTextBoxColumn

     

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 13 Apr 2018 Link to this post

    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.
  5. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 16 Apr 2018 in reply to Dimitar Link to this post

    Hi Dimitar,

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

    How we get value of typed text in TextBoxItem_KeyPress event

     

  6. Answer
    Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 16 Apr 2018 Link to this post

    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.
  7. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 16 Apr 2018 in reply to Dimitar Link to this post

    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.

  8. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 16 Apr 2018 Link to this post

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

  9. Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 17 Apr 2018 Link to this post

    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.
  10. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 17 Apr 2018 in reply to Dimitar Link to this post

    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

     

     

  11. Answer
    Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 17 Apr 2018 Link to this post

    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.
  12. rajasekar
    rajasekar avatar
    9 posts
    Member since:
    Jun 2016

    Posted 17 Apr 2018 Link to this post

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

  13. Shahid
    Shahid avatar
    2 posts
    Member since:
    Jun 2019

    Posted 06 Jun in reply to Dimitar Link to this post

    Tab key is not working in TextBoxItem_KeyDown event for DropDown.
  14. Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 06 Jun Link to this post

    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.
  15. Shahid
    Shahid avatar
    2 posts
    Member since:
    Jun 2019

    Posted 07 Jun in reply to Dimitar Link to this post

    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?

  16. Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 07 Jun Link to this post

    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.
Back to Top