The new TemplateField class only seems to work on properties directly on the DataItem. However, I have a case where I want to combine several properties into one field. Previously I used an UnboundField and a custom ControlHostEditor as described elsewhere in this forum.
Do I still have to use ControlHostEditor for this scenario?
Can you suggest a way to do this without CellValuePresenterStyle or ControlHostEditor?
Hello,
The behavior is expected and the thing you can do is to handle the XamDataGrid's EditModeEnding event and in the handler you can check id the edited cell is in the AddNewRecord. If it is you can force the new record to be added by calling the XamDataGrid's RecordManger's CommitAddRecord method. Here is a code snippet you can use:
private void XamDataGrid_EditModeEnding(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndingEventArgs e) { if (e.Cell.Record.IsAddRecord) { (sender as XamDataGrid).RecordManager.CommitAddRecord(); } }
Hope this helps you.
I've used the sample I found here but have another issue with it: Editing an unbound TemplateField does not Trigger the control to add a new record. You Need to have at least one bound field so adding the new record gets triggered. Can you reproduce this behavior? Is there any way to fix it?
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
I modified the sample you sent to test the answer to my question and found that I can use AlternateBinding on the TemplateField to solve the problem of my original question. Thank you!
<Grid> <igDP:XamDataGrid DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="True"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field BindingType="Unbound" AlternateBinding="{Binding Address.Name}" Label="Street Name"/> <igDP:Field Name="Address" Visibility="Collapsed"/> <igDP:Field BindingType="Unbound" AlternateBinding="{Binding Address.Number}" Label="Street Number"/> <igDP:TemplateField Label="Template Field" AlternateBinding="{Binding Address}"> <igDP:TemplateField.DisplayTemplate> <DataTemplate> <TextBlock> <Run Text="{Binding Name}" /> <Run Text=" -- " /> <Run Text="{Binding Number}" /> </TextBlock> </DataTemplate> </igDP:TemplateField.DisplayTemplate> <igDP:TemplateField.EditTemplate> <DataTemplate> <igEditors:XamTextEditor Value="{Binding Name}" /> </DataTemplate> </igDP:TemplateField.EditTemplate> </igDP:TemplateField> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid>
I have been out of the office since your last reply. Are you saying that I can set the BindingType of a TemplateField to Unbound and set the AlternateBinding to a Binding expression that gets me the datacontext I need for my Template?