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

Best Practice for Closing RadComboEditor on Item Selection

5 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cameron Hart
Top achievements
Rank 1
Cameron Hart asked on 19 May 2009, 10:03 PM
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:

        private void gvwManifestLines_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
        { 
            if (e.ColumnIndex == this.gvwManifestLines.Columns["saturdayDelivery"].Index) 
            { 
                // A whole bunch of code omitted. 
            } 
            else if (e.ColumnIndex == this.gvwManifestLines.Columns["PackageChooser"].Index) 
            { 
                RadComboBoxEditor comboEditor = this.gvwManifestLines.ActiveEditor as RadComboBoxEditor; 
                comboEditor.DropDownStyle = RadDropDownStyle.DropDownList; 
                comboEditor.AutoCompleteMode = AutoCompleteMode.Suggest; 
                comboEditor.PopupClosed += new RadPopupClosedEventHandler(comboEditor_PopupClosed); 
 
                //More code for processing - not relevant. 
            } 
        } 
 
        void comboEditor_PopupClosed(object sender, RadPopupClosedEventArgs args) 
        { 
            RadComboBoxEditor comboEditor = sender as RadComboBoxEditor; 
            if (comboEditor != null
            { 
                comboEditor.PopupClosed -= new RadPopupClosedEventHandler(comboEditor_PopupClosed); 
                SendKeys.Send("\r"); 
            } 
        } 
 

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.

5 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 20 May 2009, 09:42 AM
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.
0
Cameron Hart
Top achievements
Rank 1
answered on 20 May 2009, 09:43 PM
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. ^_^
0
Jack
Telerik team
answered on 21 May 2009, 08:18 AM
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.
0
Clyde
Top achievements
Rank 1
answered on 05 Nov 2010, 01:16 AM
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.
0
Jack
Telerik team
answered on 11 Nov 2010, 05:42 PM
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
Tags
GridView
Asked by
Cameron Hart
Top achievements
Rank 1
Answers by
Jack
Telerik team
Cameron Hart
Top achievements
Rank 1
Clyde
Top achievements
Rank 1
Share this question
or