<igDP:XamDataGrid> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowEdit="False"/> </igDP:XamDataGrid.FieldSettings> </igDP:XamDataGrid>
By default, editing cell values through the UI is enabled. To disable cell editing through the UI, set the FieldSettings' AllowEdit property to False, as shown in the following example, which disables editing for all cells:
<igDP:XamDataGrid> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowEdit="False"/> </igDP:XamDataGrid.FieldSettings> </igDP:XamDataGrid>
The CellValuePresenter, which represents the cell in the UI, looks for a ContentPresenter in its visual tree with the name "PART_EditorSite". If one is found, an appropriate ValueEditor derived class is instantiated and set as the ContentPresenter’s Content. This editor will start Edit mode when it is clicked or when the user pressed the F2 key, based on the CellClickAction property setting.
When F2 is pressed again, the editor will enter out of edit mode.
You can specify the type of editor that is created and how the cell is styled using the following properties in the FieldSettings class:
EditorType — Must be set to a type that derives from ValueEditor that can effectively edit the data. For example, it wouldn’t make sense to specify a XamDateTimeEditor to edit a field whose DataType property is set to Decimal.
EditAsType — If the EditorType property (described above) was not specified, this property is used to determine the editor type to create based on the editor type that is registered as the default for the EditAsType (see ValueEditor’s RegisterDefaultEditorForType method). If EditAsType is not set, the field’s DataType is used instead for the same purpose.
EditorStyle — This property is used to specify any editor-related property settings.
EditorStyleSelector — You can provide an object here that derives from StyleSelector. Its SelectStyle method will be called for each cell so that different styles can be applied on a cell-by-cell basis.
The Cell class also exposes EditorType, EditAsType, and EditorStyle properties for specifying editor settings on a cell-by-cell basis. However, these properties cannot be set in XAML. They are normally set in a handler for the InitializeRecord event. The following example code sets the ReadOnly property on the editor for the "Salary" field’s cell for DataRecords, where the "Department" is "Sales":
private void OnInitializeRecord(object sender, InitializeRecordEventArgs e) { DataRecord dr = e.Record as DataRecord; if (dr != null) { if ("Sales" == (string)dr.Cells["Department"].Value) { Style style = new Style(typeof(XamCurrencyEditor)); style.Setters.Add( new Setter(XamCurrencyEditor.ReadOnlyProperty, true)); dr.Cells["Salary"].EditorStyle = style; } } }