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.