I am trying to create a custom ValueEditor called DoubleValueEditor, and then have a control associated with that type.
The control that will appear when editing starts is a button that fills the cell with the text "Double {CellValue}".
When clicking the button, it will double the value in the cell and set it in the cell, then end edit mode.
I can get the button to appear, but am unable to have the button show the original value in the cell, and then set the cell value to the doubled amount when clicked.
Is there a sample I can access that shows this?
Thanks
Hello,
I am not quite sure exactly what you want to display in the cell but if you only want the content of the button to change when clicked you can use a Converter on the Content property.
I have created a sample demonstrating this. It is based on this thread which provides more details on hosting controls in a XamDataGrid cell: http://es.infragistics.com/community/blogs/andrew_smith/archive/2009/03/27/hosting-wpf-controls-in-a-xamdatagrid-cell.aspx
Please let me know if you have any questions.
Sincerely,
Valerie
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
Here is what I am looking for:
Not in Edit Mode: The cell looks like a normal cell - with value 5
Edit Mode Started: The cell changes to a button that shows the text Double and the cells original value - Double 5
The user clicks on the button
Edit mode ends, cell returns to normal cell - but now the value is 10.
It is actually how to create the button control, and make it have access to the cell value - to read and write.
Also, the editor and edit template needs to be assigned dynamically when the XamDataGrid raises the EditModeStarting, and be removed when the EditModeEnded is raised
If you change the field to AllowEdit=true in the prior sample and set the template as the EditDataTemplate it will only show the button in edit mode.
You can also use the grid's DataPresenterCommands to exit edit mode when the button in clicked.
Please see modified sample.
Sincerely,Valerie Developer Support Supervisor - XAMLInfragisticswww.infragistics.com/support
Thanks, this almost exactly what I want...
Just one last question. I will be building the field layout in code, and attaching the editor based on the data feed settings. Each editor could have a different data template.
I have the following (from modifying your sample):
Field editField = new Field("Amount"); editField.Settings.AllowEdit = true; Style editorStyle = new Style(typeof(ControlHostEditor)); editorStyle.Setters.Add(new Setter(ControlHostEditor.EditDataTemplateProperty, template)); editField.Settings.EditorStyle = editorStyle;
But whenever the grid appears, I don't see anything in the field. How do I recreate this in code. Also, is it possible just to change the FieldSettings after the field layout is initialized and have it work?
<igDP:Field Name="Amount" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igSamples:ControlHostEditor}"> <Setter Property="EditDataTemplate" Value="{StaticResource doubleRenderTemplate}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
You can let the grid generate the field layout automatically and then set the additional field settings in the FieldLayoutInitialized event:
private void XDG1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
{
// check if it is the field layout to modify based on the underlying object name
if (e.FieldLayout.Key.ToString() == "GridData")
// get the field to add the editor to
Field field = e.FieldLayout.Fields["Amount"];
if (field != null)
FieldSettings fs = new FieldSettings();
fs.AllowEdit = true;
// Get DataTemplate from Grid's resources
DataTemplate dt = XDG1.Resources["doubleRenderTemplate"] as DataTemplate;
Style style = new Style(typeof(ControlHostEditor));
style.Setters.Add(new Setter(ControlHostEditor.EditDataTemplateProperty, dt));
fs.EditorStyle = style;
field.Settings = fs;
}
I have attached the modified sample demonstrating this.
Do you have any other questions on this matter?