I have a XamDataGrid that I need the ability to add a new record but not edit existing records.
To get to where I am now, I have set the following:
grid.FieldLayoutSettings.AllowAddNew = true
for each column that the user can edit (some should not be editable): col.Settings.AllowEdit = true
in the OnEditModeStarting event, I check if the if e.Cell.Record.IsAddRecord is true. If not, I cancel the event.
This works ok, but has the following effects that need to be rectified:
1. For columns that use a XamComboEditor or date editor as the editor, the down arrow icon shows up on mouse-over for every cell in the column, whereas I need it to show up only for the AddRecord.
2. For existing rows, I am capturing a doubleclick event to open a details screen. I use the OnSelectedItemsChanged event to keep track of selected records.When I double-click on a non-editable column, the event fires as expected.When I doubleclick on an editable column, the OnSelectedItemsChanged event runs with no items selected, the OnDoubleClick event runs but nothing is selected at that point so event does not perform action the OnEditModeStarting event runs and is cancelled as expected the OnSelectedItemsChanged event runs with 1 Record selected.
If there is some way to turn off the ability to edit existing records, these side effects would not happen. Is there any way to come to a solution on this?
Hello David,
Thank you for your post. I have been looking into it and I suggest you create Styles for the XamComboEditor and XamDateTimeEditor and set their DropDownDisplayMode Properties to OnlyInEditMode to solve your first issue and for the second one I can suggest you set the XamDataGrid’s FieldSettings’ CellClickAction Property to SelectRecord. Please let me know if this helps you or you need further clarifications on this matter.
Looking forward for your reply.
Thanks Stefan,
Your suggestions of setting the XamComboEditor style works ok and stands as a solution to my first issue. The Property in question is DropDownButtonDisplayMode
<Style x:Key="ComboEditorStyle" TargetType="{x:Type igEditors:XamComboEditor}" BasedOn="{StaticResource {x:Type igEditors:XamComboEditor}}"> <Setter Property="DropDownButtonDisplayMode" Value="OnlyInEditMode"/> </Style>
For your second point about setting the CellClickAction -- this is already the case that the CellClickAction is SelectRecord. This does not, however, prevent a cell from trying to go in to edit mode, which deselects the row. Still need a solution for this.
I should note that I will still need the double-click action to go in to edit mode on the New Record line, so it would not be a solution to disable double-clicking from going into edit mode for the entire grid. I need to be able to add a new record (i.e. edit those cells) but not edit existing records.
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
Hi Stefan,
This solution works okay, but unfortunately this makes every cell in a given column editable, as opposed to the cell in the specified record. While I was able to get this to work, it requires a bit of babysitting the editable flag (making sure to turn it off when you are done editing, turning it on for keyboard shortcut, etc).
Is there a way to make a cell editable without making the entire column editable?
Hello,
I have been looking into your requirement and I can say that the AllowEdit Property can only be set to the entire Field, so I believe the best approach in this case is to do so and set it back to False, when you exit EditMode. Please let me know if you need further clarifications on this matter.