Now I just wat to change "AllowEdit = true" into "AllowEdit = false" for specific Cell in the source code.
First I tried like the following .
CellValuePresenter.FromCell((xamDataGrid1.Records[5] as DataRecord).Cells[0] as Cell).Field.Settings.AllowEdit = false;
but It made all cells having 0 index of records un-editable.
In the brief , I Just want to set the property "AllowEdit" to false for one or specific cell not all records cell.
Thanks in advance.
Hello Kathleen,
If you want to be able to edit a single Record, based on a condition, you can handle the XamDataGrid’s EditModeStarting event and determine whether to cancel it or not. I attached a sample project for you showing you how to do so. Please let me know if you need more clarifications on this matter.
Looking forward for your reply.
Hi,
I need help please, i want to do an specific row of my XamDataGrid allow to edit, i am using this command:
Me.xdgOrdenes.Records(2).FieldLayout.FieldSettings.AllowEdit = True
But all the records (rows) are available to edit, can you help me please to do just one specific row available to edit.
Thank you.
I would like to know how this can be bound in XAML without having to write any C# and just bind a specific cell's AllowEdit property. I have tried binding the FieldSettings.AllowEdit to a property in my ViewModel, and yes, it sets the "AllowEdit" for the entire column based off of another neighboring column's Checkbox being checked (only the first one though!). I just would like this one specific cell to have the AllowEdit change applied, not the Field. How do I specify something along the wishful syntax of <igDP:RowSetting.AllowEdit> somewhere? I super appreciate your response!!!
I had a similar problem and set the IsReadOnly Property in XAML. After that there was still a problem with the StartEditMode. The Editor went into EditMode, although the IsReadOnly was set to true. The value was not changeable, but the visible Style in the grid was changed to the editor style. I think this is not what most of the people expect the Editor to behave when in IsReadOnly mode.I solved this problem by wrapping XamDataGrid and overwriting OnEditModeStarting Event. There I looked for IsReadOnly on the Editor and if that was true, I canceled the Event.
Is there a better solution for this?
Here is my solution. First, the XAML code for the CellValuePresenter Style. If you want standard behaviour, you should add the standard CellValuePresenter ControlTemplate (like I did in here):
...<igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource MainCellValuePresenterStyle}" /></igDP:XamDataGrid.FieldSettings>...
<Style x:Key="MainCellValuePresenterStyle"TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"><igWindows:CardPanel Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"><Border x:Name="MainBorder" CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" /><Rectangle x:Name="Active" Fill="{TemplateBinding BackgroundActive}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" SnapsToDevicePixels="True" Opacity="1" Visibility="Collapsed" StrokeThickness="1" Stroke="{TemplateBinding BorderActiveBrush}" /><Rectangle VerticalAlignment="Stretch" HorizontalAlignment="Right" Stroke="{StaticResource MainColor2DarkestSolidBrush}" StrokeThickness="1" /><Rectangle VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Stroke="{StaticResource MainColor2DarkestSolidBrush}" StrokeThickness="1" /><ContentPresenter x:Name="PART_EditorSite" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Style="{TemplateBinding ForegroundStyle}" /></igWindows:CardPanel> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding DataItem.HasChildren}" Value="True"> <Setter Property="igEditors:ValueEditor.IsReadOnly" Value="false" /> </DataTrigger> </ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
protected override void OnEditModeStarting(Infragistics.Windows.DataPresenter.Events.EditModeStartingEventArgs args){ var cell = args.Cell; var cellEditor = Infragistics.Windows.DataPresenter.CellValuePresenter.FromCell(cell).Editor; if (cellEditor != null && !cellEditor.IsReadOnly) base.OnEditModeStarting(args); else args.Cancel=true;}
This is because you are setting this property to the FieldSettings, which will apply to all of the cells in that field. You have to set this locally - on the CellValuePresenter itself and the editor actually.
You can do that like this:
CellValuePresenter cvp = CellValuePresenter.From....
cvp.Editor.IsReadOnly = false;
Please let me know if you have questions on this.