I have a xamdata grid where the first column is an unbound field that contains a custom usercontrol. The custom control contains two text boxes which allow the user to search by name or ID. There are other columns in the datagrid.
The desired behavior is that when the user types into one of the text boxes of the user control, the RecordAdded event will fire just as it does with any other bound field. I also want the the user to be able to tab from the first column to the second column, etc.
The current behavior is that when the tab key is pressed and the cursor is in one of the text boxes of the user control, the cursor moves to the next ROW (should be next COLUMN). Also the Row added and row updated events do not fire unless the user edits a bound field. See the xaml fragment below. The bindings work correctly visually i.e. I can see the bound data in the grid.
</igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields>
<igDP:UnboundField Label="Account" Width="450"> <igDP:UnboundField.Settings> <igDP:FieldSettings AllowEdit="True" > <igDP:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <samsControls:Selector Width="450" IDTitle="Account No:" DescTitle="Account Name:" Layout="Horizontal" TitleLayout="Horizontal" IDTitleWidth="80" DescTitleWidth="90" IDSearchTextBoxWidth="70" DescSearchTextBoxWidth="210" SelectedID="{Binding DataItem.ACCT_NO, Mode=TwoWay}" SelectedDesc="{Binding DataItem.AccountName, Mode=TwoWay}" Selecting="Account_Selecting"> </samsControls:Selector> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.CellValuePresenterStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField>
<igDP:Field Name="QUANTITY" Label="Quantity" Width="80"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource Decimal5Style}"> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Hello Sam,
Thank you for posting to our community.
I have been looking into the provided code snippet and I created a sample project based on it. It seems that on my side when the tab button is pressed the cursor moves to the next field not to the next record. Would you look at the attached project and let me know if I had missed something in your scenario?
When the whole template of the CellValuePresenter is changed, some of the functionality may be lost. It seems that this is the reason why the RecordUpdated event is not fired. You can use the default template of the CellValuePresenter located in the DataPresenterGeneric_Express.xaml file in C:\Program Files (x86)\Infragistics\NetAdvantage 2012.2\WPF\DefaultStyles\DataPresenter and add the functionality you need to it. More information regarding a similar issue could be found in this forum post: http://ko.infragistics.com/community/forums/p/7462/289274.aspx
Please feel free to let me know if you have any other questions.
Thank you Maria, After reviewing your example I think the best approach for me is to not put two editable controls in a single column because tabing just doesn't work. I will continue to work on this, will no doubt have further questions.
Regards,
Sam
If tabbing is the issue you are concerned with then you might be able to do this if you do something like what I describe in my blog post here using a custom ValueEditor instead of removing the editor from the CellValuePresenter.
Andrew, thank you for your sample code. I tried to use it in my project but I cannot get it to work.
In the attached project I have a xamdata grid with four columns, each of which hosts my custom control.
Issues:
The main problem I would like to fix is the tab key does not move from column to column. It moves the active row to the next row. When the grid receives the focus I would like the user to be able to "just start typing".
The grid appears to load much slower after adding the ControlHostEditor class
Note my custom cotrol dispalys up a popup menu I need to make sure the ControlHostEditor does not handle the tab key and prevent the event from bubling up to my control
I do not understand the bindings in the ControlHostEditor
Well I think the slowness you mention is because you're using UnboundField for those fields you added to use the ControlHostEditor. BTW since you weren't specifying any Binding or BindingPath for the UnboundField it was showing up blank. In your case it doesn't seem like there is any reason to use an UnboundField - just use Field as you were before but use the ControlHostEditor for the editor.Another slowness is going to come from the fact that your SelectorTextBox basically makes a copy of the ItemsSource collection (in the Loaded handler) and since you're showing that always that is going to be slow with your 100,000 items. If you don't need to do any mapping of id to value then you might want to consider leaving only the EditDataTemplate and not setting the Template of editor to the EditTemplate so the control is only created when it goes into edit mode (and therefore the Loaded of only 1 SelectedTextBox control is fired at a time and only when going into edit mode). If you do need mapping you might still considering doing it some other way - perhaps a ValueToDisplayTextConverter that maps the id to the value using a dictionary or some other efficient lookup/conversion. And actually if you're going to use our filtering ui for those fields (as you are in your sample) then you'll likely need to do something like the ValueToDisplayTextConverter because you'll presumably want the display name in the filtering dropdowns.BTW the ItemsSource wasn't really working in your sample because you were trying to do an ElementName binding across namescopes. The Style/DataTemplate each have their own Namescope and the Window/UserControl each have their own namescope. The snippet below uses the DataPresenter of the hosting CellValuePresenter to get to the People collection.
ItemsSource="{Binding Path=(local:ControlHostEditor.Editor).Host.DataPresenter.DataContext.People, RelativeSource={RelativeSource Self}}"
<igDP:XamDataGrid x:Name="grid" DataSource="{Binding Trades}"> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings Width="*" AllowRecordFiltering="True" FilterLabelIconDropDownType="MultiSelectExcelStyle" CellClickAction="EnterEditModeIfAllowed"/> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowDelete="True" AllowAddNew="True" AddNewRecordLocation="OnTop" AllowFieldMoving="WithinLogicalRow" AutoGenerateFields="False" HighlightAlternateRecords="True" FilterUIType="LabelIcons" MaxSelectedRecords="1"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="ACCT_NO" Label="Acct No" Width="130"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="local:ControlHostEditor"> <Setter Property="ValueType" Value="{x:Type system:String}" /> <Setter Property="EditDataTemplate"> <Setter.Value> <DataTemplate> <samsControls:SelectorTextBox SelectedValue="{Binding RelativeSource={RelativeSource Self}, Path=(local:ControlHostEditor.Editor).Value}" SelectionChanged="SelectorTextBox_SelectionChanged" ItemsSource="{Binding Path=(local:ControlHostEditor.Editor).Host.DataPresenter.DataContext.People, RelativeSource={RelativeSource Self}}" DisplayMemberPath="Name" SelectedValuePath="ID" SearchTermType="ID" ResultsListWidth="400"> </samsControls:SelectorTextBox> </DataTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="ACCT_Name" Label="Acct Name" Width="130"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="local:ControlHostEditor"> <Setter Property="ValueType" Value="{x:Type system:String}" /> <Setter Property="EditDataTemplate"> <Setter.Value> <DataTemplate> <samsControls:SelectorTextBox SelectedValue="{Binding RelativeSource={RelativeSource Self}, Path=(local:ControlHostEditor.Editor).Value}" SelectionChanged="SelectorTextBox_SelectionChanged" ItemsSource="{Binding Path=(local:ControlHostEditor.Editor).Host.DataPresenter.DataContext.People, RelativeSource={RelativeSource Self}}" DisplayMemberPath="Name" SelectedValuePath="ID" SearchTermType="Description" ResultsListWidth="400"> </samsControls:SelectorTextBox> </DataTemplate> </Setter.Value> </Setter> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Andrew thank you very much for your code, it works great! I could not have done it myself, thanks again.