I have a form where users enter some data and then submit.
If the XamMultiColumnComboEditor is the last field they want to enter, and they have the dropdown open, and they have an item selected in the dropdown and they execute the submit command, the selected item in the dropdown does not get pushed out to the binding target.
The only thing I've been able to do is a hack like so to simulate the enter keypress on that control, if the dropdown is detected to be open:
{
// Gets the element with keyboard focus.
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
var routedEvent = Keyboard.KeyDownEvent; // Event to send
elementWithFocus.RaiseEvent(
new KeyEventArgs(
Keyboard.PrimaryDevice,
PresentationSource.FromVisual(elementWithFocus),
0, Key.Enter)
{ RoutedEvent=routedEvent });
}
Is there a less hacky way to accept the value selected in the dropdown and get binding targets to be updated?
I've spent some time (enough of it) in the source to believe that I need to somehow execute a method
CommitTextAsSelected
on ComboEditorBase. But there is no public accessibility to get to it, insofar as I can tell. Maybe I'm thinking about this wrong. Please let me know.
Thanks, David
Hello dbeavon,
Thank you for your reply. I am glad that the recommendations that I had made allow your drop-down's selected item to work in the way that you wish for it to work.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
This is great.
I altered your sample slightly. The button becomes "_Submit" with a shortcut. You can see that, at the moment when the dropdown is open, if the user hits ALT-S, the highlighted item becomes the selected item. (and a mesagebox is shown to say as much)
Without your recommendation, that would not have happened properly.
See attached.
Thank you for clarifying your requirement a bit more. I believe that I fully understand it now, and I believe I now have a procedure that will allow you to do this.
To do this, prior to programmatically closing the XamMultiColumnComboEditor's drop-down, I would recommend that you look into the XamMultiColumnComboEditor's Items collection. This collection will be full of ComboRow items, and the one that is highlighted will have its IsFocused property set to "true." From this ComboRow, you can get the underlying data item from the Data property of the ComboRow, and set that to the SelectedItem of the XamMultiColumnComboEditor. Then, you can shut the drop-down and verify that the SelectedItem should be pushed into your ViewModel.
I have attached a sample project to demonstrate the above. I hope this helps you.
We don't want just ANY selection, we want the one that was highlighted in the drop-down (popup window) at the moment when the submit command was executed. IE. It is the one that "appears" to be highlighted/selected, even though the user hasn't hit <tab> or <enter> key yet.
You and I both know that it is not "quite" selected yet .. . but the user can trigger the submit command while the popup is still open and they expect it to "just work".
Please let me know if this is not clear.
The selection is not updated simply because the drop-down is closed because the XamMultiColumnComboEditor has not received any sort of indication from the user that it should perform a selection. For example, typing into the combo's editor is not a selection input, because the user can have the ability to type something that doesn't exist in the combo. If this happens, the combo editor cannot select that particular item, because that item doesn't actually exist in the editor.
I suppose it may be possible to get the CommitTextAsSelected method using Reflection, but I'm not entirely sure as it is a private method, meant for internal use. I do think I may have an alternative workaround for you on this matter, though.
The actual text editor that exists inside of the XamMultiColumnComboEditor is an element called SpecializedTextBox. You may be able to utilize this element and its Text property when trying to commit the selected item of your XamMultiColumnComboEditor on close of the drop-down. To do this, I would recommend that you continue with the drop-down closing in your 'submit' command, but then you can use the Infragistics.Windows.Utilities class to get this SpecializedTextBox. You can do this using the following code, where 'XMCCE' is the XamMultiColumnComboEditor:
SpecializedTextBox text = Utilities.GetDescendantFromType(XMCCE, typeof(SpecializedTextBox), false) as SpecializedTextBox;
Once you have this textbox, you can check it's Text property against the items that exist in your data source of the XamMultiColumnComboEditor. You could perhaps base this search off of the property used for your combo's DisplayMemberPath. If you find an item that is a complete match to one of the items in your combo, you can mark it as the SelectedItem of your XamMultiColumnComboEditor to ensure that there is an item selected. If no item is found, or multiple items are found that match the criteria, you may want to consider clearing the text of the SpecializedTextBox (set Text property to ""), and prompting your users to select an item in the combo editor.
I hope this helps. Please let me know if you have any other questions or concerns on this matter.