GridViewComboBoxColumn contents not appearing on first time click only

2 posts, 0 answers
  1. David Simmonds
    David Simmonds avatar
    56 posts
    Member since:
    Mar 2010

    Posted 18 Jan 2012 Link to this post

    I have a GridView with a GridViewComboBox column. I create a datasource in the Load handler of the form but do not assign it to the GridViewComboBox yet. The datasource is an IQueryable object and is located in the class accessible to all methods of the class.

    private IQueryable<BUILDING> dataBuildings;

    The GridViewComboBox datasource gets assigned in the CellEditorInitialized event handler of the gridView.

    When the app runs and I click in the cell with the combobox, the contents of the dropdown are empty but the size of the dropdown is as if it were filled. If I click on another cell, same row or another row, and then click back into the combobox cell, the contents are filled as expected.

    Why would this be?
  2. Jack
    Jack avatar
    2333 posts

    Posted 23 Jan 2012 Link to this post

    Hi David,

    We were not able to reproduce this issue. However, we do not recommend setting the DataSource property every time when starting an edit operation. Instead, you can set the DataSource property to GridViewComboBoxColumn and use filtering to change visible items. Please, consider the code snippet below which demonstrates this scenario:

    private void Form1_Load(object sender, EventArgs e)       
        radGridView1.CellEditorInitialized += new GridViewCellEventHandler(radGridView_CellEditorInitialized);           
        radGridView1.Columns.Add("CategoryName", "Category", "Name");
        DataTable products = new DataTable();
        products.Columns.Add("ID", typeof(int));
        products.Columns.Add("ProductID", typeof(int));
        products.Columns.Add("Name", typeof(string));
        products.Rows.Add(1, 1, "Apple");
        products.Rows.Add(2, 1, "Melon");
        products.Rows.Add(3, 1, "Cherry");
        products.Rows.Add(4, 2, "Tomato");
        products.Rows.Add(5, 2, "Cucumber");
        products.Rows.Add(6, 2, "Potato");
        GridViewComboBoxColumn comboBoxColumn = new GridViewComboBoxColumn("Product", "Product");
        comboBoxColumn.DisplayMember = "Name";
        comboBoxColumn.ValueMember = "ID";
        comboBoxColumn.DataSource = products;
        comboBoxColumn.Width = 250;
        radGridView1.Rows.Add("Fruits", 1);
        radGridView1.Rows.Add("Vegetables", 4);
    private bool PerformFiltering(RadListDataItem item)
        DataRowView row = (DataRowView)item.DataBoundItem;
        string category = this.radGridView1.CurrentRow.Cells["CategoryName"].Value.ToString();
        if (category == "Fruits")
            return (int)row["ProductID"] == 1;
        return (int)row["ProductID"] == 2;
    void radGridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        if (e.ColumnIndex == 1)
            if (this.radGridView1.CurrentRow.Cells[0].Value != null)
                RadDropDownListEditor editor = this.radGridView1.ActiveEditor as RadDropDownListEditor;
                if (editor != null)
                    RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
                    editorElement.SelectedValue = null;
                    editorElement.Filter = PerformFiltering;
                    editorElement.SelectedValue = radGridView1.CurrentCell.Value;

    I hope this helps. If you continue to experience this issue, please send us a sample project which reproduces it and we will try to find the best option.

    Regarding the drop down size, RadDropDownListElement has a default size and it will show its popup even when there are no items.

    Should you have any other questions, we will be glad to help.
    All the best,
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top