Hi there
I’m using WPF Infragistic 2011 V2 XamDatagrid. The application is based on MVVM. I need to make some of the records editable while the rest of the rows remain readonly based on a Boolean property (IsReadOnly) in my model. It appears to be such a simple task but I can’t find an example of how to do it without writing code behind. Please help.
Regards
Boris
Unfortunatelly our only option is XAML
Hi Boris,
The simplist way that I can think of (in code behind) would be to handle the RecordDeleting event and cancel it.
private void xamDataGrid1_RecordsDeleting(object sender,
Infragistics.Windows.DataPresenter.Events.RecordsDeletingEventArgs e)
{
foreach (DataRecord dr in e.Records)
if ((bool)dr.Cells[2].Value == true)
e.DisplayPromptMessage = false;
e.Cancel = true;
e.Handled = true;
}
Would this work or you want to do it in XAML?
Sam
Hi Sam
Thank you for your help. The grid works now as expected. For the benefit of other developers I'm uploading the sample with all the changes applied.
One question remains thou - How can I prevent read only rows from being deleted? But for this I'll start another thread with appropriate subject.
Thanks again
Thank you for providing me with your implementation.
I used a different approach for data triggers. Instead of using CellValuePresenter, I used the editors for corresponding editors such as XamNumericEditor for Value and XamTextEditor for Label.
Please replace the control template that targets CellValuePresenter with the following Style I pasted below, and add one more for XamTextEditor. Also in the FieldSettings instead of CellValuePresenterStyle, use EditorStyle such as:
<igDP:FieldSettings EditorStyle="{StaticResource ValueEditorStyle}"/>
<Style x:Key="ValueEditorStyle"
TargetType="{x:Type igEditors:XamNumericEditor}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Cells[2].Value}" Value="True">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Cells[2].Value}" Value="False">
<Setter Property="IsEnabled" Value="True"/>
</Style.Triggers>
</Style>
Let me know how this worked for you. I tested it here, and it displayed the field errors as I would expect.
Thanks,
Run the sample, enter any value less than a 100 into Value field - observe both the Record and the Field level errors. Please note that Readonly check box has no effect.
Go to XAML and uncomment the following code:
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource ValueEditorStyle}"/>
</igDP:Field.Settings>
Readonly functionality is active now but Field level errors are not displayed
Cheers