Ingragistic XamGrid: New record is not editable
-
07-02-2021 - |
Question
Given,
<igDP:XamDataGrid Name="dataGrid"
DataSource="{Binding RecordList}">
<igDP:XamDataGrid.FieldLayoutSettings >
<igDP:FieldLayoutSettings AllowAddNew="true" AddNewRecordLocation="OnTopFixed"/>
</igDP:XamDataGrid.FieldLayoutSettings>
On running, I can see a empty new row on top of the grid. But none of the columns in the new row are editable !!! The columns are editable when I mark each of the Fields as editable.
Is it possible to have the add record functionality work while "without" explicitly marking each of the fields as editable ?
Thanks for your interest.
Solution
You best bet would be asking this on the infragistics netadvantage forum, but having said that...
As I understand what you want is a readonly datagrid (non-editable on its cells) to have a editable row to add new item...
- Add a
CellValuePresenter
targettedStyle
underXamDatagrid.Resources
. - This will check if the given cell value presenter is focused and represents the add new row.
If so it will make the parent field editable via some attached behavior.
<igDP:XamDataGrid Grid.Row="1" DataSource="{Binding}" AutoFit="True"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding IsFocused, RelativeSource={RelativeSource Self}}" Value="True"/> <Condition Binding="{Binding Record.IsAddRecord, RelativeSource={RelativeSource Self}}" Value="True"/> </MultiDataTrigger.Conditions> <Setter Property="local:CellValuePresenterBehavior.AllowFieldEdit" Value="True"/> </MultiDataTrigger> </Style.Triggers> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <!-- Only show the first 4 fields to keep the display simple --> <igDP:Field Name="Key" Visibility="Visible"> <igDP:Field.Settings> <igDP:FieldSettings EditAsType="{x:Type System:String}" EditorType="{x:Type Editors:XamTextEditor}" AllowEdit="False"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Value" Visibility="Visible"> <igDP:Field.Settings> <igDP:FieldSettings EditAsType="{x:Type System:String}" EditorType="{x:Type Editors:XamTextEditor}" AllowEdit="False"/> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" AllowAddNew="True" AddNewRecordLocation="OnTopFixed" HighlightAlternateRecords="True"/> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid>
And the attached behavior is as below...
public class CellValuePresenterBehavior
{
public static DependencyProperty AllowFieldEditProperty
= DependencyProperty.RegisterAttached(
"AllowFieldEdit",
typeof(bool),
typeof(CellValuePresenterBehavior),
new PropertyMetadata(false, OnAllowFieldEditChanged));
private static void OnAllowFieldEditChanged(
DependencyObject depObj,
DependencyPropertyChangedEventArgs args)
{
var cvp = depObj as CellValuePresenter;
if (cvp != null)
{
cvp.Field.Settings.AllowEdit = (bool)args.NewValue;
}
}
public static bool GetAllowFieldEdit(DependencyObject depObj)
{
return (bool) depObj.GetValue(AllowFieldEditProperty);
}
public static void SetAllowFieldEdit(DependencyObject depObj, bool value)
{
depObj.SetValue(AllowFieldEditProperty, value);
}
}
Hope this helps.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow