Hi All,
I have an editable XamDataGrid that is bound to a data source. I have a button that causes a new item to be added to my data source collection programmatically. I want the first column of this new row, which contains a XamComboEditor to grab focus so that the user can type in and have the matching item in the list selected without having to click on the cell with the mouse. Is this possible in an MVVM style, if so, how?
Thanks in advance
Russell
Hello,
I am just checking your progress on the issue.
If you require any further assistance please do not hesitate to ask .
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics
www.infragistics.com/support
I have been looking into your question and what can be done in xaml can be done in the codebehind, but the opposite is not always true . In order to implement your goal, you can use the codebehind, and put the desired cell in edit mode at some specific moment, for example when your datasource has been updated or in a handler when the grid raises an event. The following code sets the first cell of the first row in edit mode:
xamDataGrid1.ActiveCell =
(xamDataGrid1.Records[0] as DataRecord).Cells[0];
private void xamDataGrid1_CellActivated(object sender, Infragistics.Windows.DataPresenter.Events.CellActivatedEventArgs e)
{
xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);
}
Please let me know if you need some further assistance regarding the discussed matter.
Infragistics, Inc.
I tried adding an IsFocussed property to the rowItem then created an attached property to listen to changes in that property. When the property changed I then called StartEditMode() on the XamComboEditor which put focus on the editor. However, after this point the user is no longer able to tab away fromt he XamComboEditor to the next cell in the row or even click on the next cell in the row to select it.
This was the style to add the attached property to the XamComboEditor...
<Style TargetType="{x:Type Editors:XamComboEditor}"> <Setter Property="AttachedProperties:FocusAttachedProperties.IsFocused" Value="{Binding DataItem.IsFocussed}" /> </Style>And this is the body of the attached property...
public static class FocusAttachedProperties { public static bool GetIsFocused(DependencyObject obj) { return (bool)obj.GetValue(IsFocusedProperty); } public static void SetIsFocused(DependencyObject obj, bool value) { obj.SetValue(IsFocusedProperty, value); } public static readonly DependencyProperty IsFocusedProperty = DependencyProperty.RegisterAttached( "IsFocused", typeof(bool), typeof(FocusAttachedProperties), new UIPropertyMetadata(false, OnIsFocusedPropertyChanged)); private static void OnIsFocusedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uiElement = (UIElement)d; if ((bool)e.NewValue) { var xamComboEditor = (XamComboEditor)d; xamComboEditor.StartEditMode(); } } }
Any ideas on other ways to achieve this or how to stop the StartEditMode() from stopping tabbing / relinquishing focus?