Best Practice for Closing RadComboEditor on Item Selection

6 posts, 1 answers
  1. Cameron Hart
    Cameron Hart avatar
    17 posts
    Member since:
    May 2008

    Posted 19 May 2009 Link to this post

    On the theme of cutting down on the user keystroke count for my application:

    I have a RadGridView. Inside that RadGridView is a radComboColumn that contains information from a BoxCode DataTable. Value is the BoxCodeTable.ID and Display is BoxCodeTable.Description.

    The BoxCode DataTable also stores length, width, and height information for a given box. When the user selects a box and the editor is closed, the length, width, and height values are loaded from the DataTable and inserted into three fields in the RadGridView's CurrentRow. The idea is that a user should be able to override these values in certain boundary conditions.

    That's all working. But it is annoying to me that, when a BoxCode is selected from the ComboBoxColumn, the user must press the Enter Key (or click elsewhere on the grid) to close the editor. I want to take that keystroke out.

    And I've managed to do that with a bit of a hack. However, it feels really, really awkward.

    In RadGridView.CellBeginEdit event, I am calling the following code to bind an event to the RadComboBoxEditor:

    1         private void gvwManifestLines_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
    2         { 
    3             if (e.ColumnIndex == this.gvwManifestLines.Columns["saturdayDelivery"].Index) 
    4             { 
    5                 // A whole bunch of code omitted. 
    6             } 
    7             else if (e.ColumnIndex == this.gvwManifestLines.Columns["PackageChooser"].Index) 
    8             { 
    9                 RadComboBoxEditor comboEditor = this.gvwManifestLines.ActiveEditor as RadComboBoxEditor; 
    10                 comboEditor.DropDownStyle = RadDropDownStyle.DropDownList; 
    11                 comboEditor.AutoCompleteMode = AutoCompleteMode.Suggest; 
    12                 comboEditor.PopupClosed += new RadPopupClosedEventHandler(comboEditor_PopupClosed); 
    13  
    14                 //More code for processing - not relevant. 
    15             } 
    16         } 
    17  
    18         void comboEditor_PopupClosed(object sender, RadPopupClosedEventArgs args) 
    19         { 
    20             RadComboBoxEditor comboEditor = sender as RadComboBoxEditor; 
    21             if (comboEditor != null
    22             { 
    23                 comboEditor.PopupClosed -= new RadPopupClosedEventHandler(comboEditor_PopupClosed); 
    24                 SendKeys.Send("\r"); 
    25             } 
    26         } 
    27  

    As you can see, I'm closing the editor by sending the return keystroke myself. This is working. I'm a bit shy about it, however. It feels a shaky to close the editor by relying on sending keystrokes. Is there a better solution to this problem?

    I tried EndEdit(), but no dice.
  2. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 20 May 2009 Link to this post

    Hello Cameron Hart,

    Thank you for contacting us.

    Calling EndEdit method should do the work. The following code worked in my test solution:

    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
        RadComboBoxEditor editor = this.radGridView1.ActiveEditor as RadComboBoxEditor; 
        if (editor != null
        { 
            editor.PopupClosed += new RadPopupClosedEventHandler(editor_PopupClosed); 
        } 
     
    void editor_PopupClosed(object sender, RadPopupClosedEventArgs args) 
        RadComboBoxEditor editor = this.radGridView1.ActiveEditor as RadComboBoxEditor; 
        if (editor != null
        { 
            editor.PopupClosed -= new RadPopupClosedEventHandler(editor_PopupClosed); 
            this.radGridView1.EndEdit(); 
        } 

    Maybe there is something specific in your application. Could you please send it to us, so we can review it and find a proper solution. You need to open a new support ticket so that you can attach files.

    I am looking forward to your reply.

    All the best,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Cameron Hart
    Cameron Hart avatar
    17 posts
    Member since:
    May 2008

    Posted 20 May 2009 Link to this post

    Ha! Wow. Now I feel foolish.

    You're right: this.radGridView1.EndEdit() does the trick.

    I had been trying to call comboEditor.EndEdit() and got confused when it wouldn't work.

    Silly me. ^_^
  5. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 21 May 2009 Link to this post

    Hi Cameron,

    I admit that this is a little confusing. You should not use BeginEdit/EndEdit methods of the editor. They are used internally in RadGridView. We will update our documentation accordingly.

    If you have any other questions, please don't hesitate to ask.

    Kind regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Clyde
    Clyde avatar
    3 posts
    Member since:
    Apr 2009

    Posted 04 Nov 2010 Link to this post

    I am in the process of upgrading our deployed assemblies from v2009.1 to v2010.2 and we had the above solution in use. The RadComboBoxEditor no longer seems to support the PopupClosed event and thus won't compile.

    Can you please clarify if this fix is still required required or what the alternative code should now be...

    Thanks.
  7. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 11 Nov 2010 Link to this post

    Hi Clyde,

    In Q2 2010 we introduced the new RadDropDownList control. It is faster and introduces several new features. This control should replace the old RadComboBox which is longer in active development. We advice our customers to replace RadCombBox with RadDropDownList. The new control is used also internally in RadGridView and your code should be changed. Please consider the code below:
    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        RadDropDownListEditor editor = this.radGridView1.ActiveEditor as RadDropDownListEditor;
        if (editor != null)
        {
            RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
            editorElement.PopupClosed += new RadPopupClosedEventHandler(editorElement_PopupClosed);
        }
    }

    I hope this helps. In case you have any further questions, I will be glad to help.

    Best wishes,
    Jack
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready