I am trying to convert my very simple wpf datagrid to the infragistics datagrid. I am not sure how to disable a specific cell based a property. I'm now using a textbox as datatemplate instead of a normal datagridtextcolumn. How can I create a similar infragistics grid (without code behind)?
The way my datagrid is setup:
<DataGrid ItemsSource="{Binding Path=MyDtos}" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Weight">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Weight, Mode=TwoWay, StringFormat=F1}" IsEnabled="{Binding Path=AllowEdit}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Path=AllowEdit, Mode=TwoWay}" Header="AllowEdit" />
</DataGrid.Columns>
</DataGrid>
Hi Femke,
I don’t think this is going to work because FieldLayoutSettings is not a FrameworkElement. You can hook to the ExecutingComand event of the XamDataGrid and to cancel it when deleting record with AllowEdit false:
xamDataGrid.ExecutingCommand += new EventHandler<ExecutingCommandEventArgs>(xamDataGrid_ExecutingCommand);
void xamDataGrid_ExecutingCommand(object sender, ExecutingCommandEventArgs e)
{
if (e.Command == DataPresenterCommands.DeleteSelectedDataRecords)
XamDataGrid grid = (XamDataGrid)sender;
DataRecord dataRecord = (DataRecord)grid.SelectedItems.Records[0];
MyDataItem dataItem = (MyDataItem)dataRecord.DataItem;
if (!dataItem.AllowEdit)
e.Cancel = true;
}
Probably you will need to change the selection mode of the grid to single select because the delete command is executed on all selected records:
xamDataGrid.FieldLayoutSettings.SelectionTypeRecord = SelectionType.Single;
Hope this helps!
Thanks,
Diyan Dimitrov
Hi,
I would also like to bind AllowDelete on AllowEdit and tried the following but it doesn't work, any ideas?:
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AllowDelete="{Binding Path=ActiveDataItem.AllowEdit, Mode=OneWay}"/>
</igDP:XamDataGrid.FieldLayoutSettings>
Femke
Hi Diyan,
This is perfect! Many thanks!!
Here is a sample code:
<igDP:XamDataGrid x:Name="xamDataGrid">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Name="Weight">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="igEditors:XamNumericEditor">
<Setter Property="IsEnabled" Value="{Binding Path=DataItem.AllowEdit, Mode=OneWay}"></Setter>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
I suppose that Weight is a numeric type, but if it is not you can change the TargetType to any other editor. Let me know if this isn’t what you need.