GridViewComboBoxColumn does not clear properly

5 posts, 1 answers
  1. Sean
    Sean avatar
    10 posts
    Member since:
    Aug 2012

    Posted 15 May 2013 Link to this post

    I have a GridViewComboBoxColumn with AutoCompleteMode = SugestAppend, and DropDownStyle = DropDown, and a DataSource of a DataSet with a blank record at the top (so a selection can be removed). If you use the drop down button and select the blank entry then the cell in the GridView clears as expected.  However, if you clear the data in the cell instead, it does not select the blank entry in the drop down list, and when you tab away from that cell the value goes back to what it was before the delete.
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 18 May 2013 Link to this post

    Hello Sean,

    A very simple workaround for this could be just registering to the CellEditorInitializedEvent and do the following:
    void gridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        var editor = e.ActiveEditor as RadDropDownListEditor;
        if (editor != null)
        {
            var editorElement = editor.EditorElement as RadDropDownListEditorElement;
            if (editorElement != null)
            {
                editorElement.TextChanged -= editorElement_TextChanged;
                editorElement.TextChanged += editorElement_TextChanged;
            }
        }
    }
     
    void editorElement_TextChanged(object sender, EventArgs e)
    {
        var editorElement = sender as RadDropDownListEditorElement;
        if (editorElement != null)
        {
            if (string.IsNullOrEmpty(editorElement.Text))
            {
                editorElement.SelectedIndex = 0;
            }
        }
    }

    Whenever an item that is not in the list will be selected, the editor.Element.Text will be string.emply so we will just set the first item as selected, thus having an emply selection.

    Hope this helps.

    Best Regards,
    Emanuel Varga MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 20 May 2013 Link to this post

    Hi Sean,

    Thank you for your question.

    The Text property is not synchronized out of the box with the SelectedIndex property and you should use the solutioin Emanuel proposed.

    @Emanuel - thank you for your cooperation. 

    Regards,
    Peter
    the Telerik team
    RadChart for WinForms is obsolete. Now what?
  5. Sean
    Sean avatar
    10 posts
    Member since:
    Aug 2012

    Posted 20 May 2013 Link to this post

    G'Day Peter,

    Yes the work around works but as far as I am concerned this is a bug that needs to be resolved.  Any text entered will be matched and verified against the list but empty text is not. Shouldn't the behaviour be the same as a stand alone control?

    Thanks,
    Sean
  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 23 May 2013 Link to this post

    Hi Sean,

    Thank you for sharing your opinion with us.

    We will consider including this when planning our future releases, if there is a demand for such a functionality. For the time being, you can continue using the provided workaround which covers this case.

    Let me know if you have additional questions.

    Regards,
    Peter
    Telerik
    RadChart for WinForms is obsolete. Now what?
Back to Top
UI for WinForms is Visual Studio 2017 Ready