Hi what i would like to do is bind the AllowEdit property of a cell to a method on the bound object called
public bool IsReadOnly(string propertyName)
where propertyName is the Column Name of the Cell
is this possible (perhaps using something like http://msdn.microsoft.com/en-us/library/aa348824.aspx)
and if so could someone help me with some example xaml style to do this (sorry i'm very new to this)
thanks in advance
Gautam
Hello Gautam,
The cell does not have a suitable property that you can bind to to make it read only. The Field's Settings have but that would make all the cells in that field read only. I am also not sure if this method will be appropriate of achieving this. The easiest and quickest way to achieve this using your approach is to handle the EditModeStarting method and set the e.Cancel to the result of the IsReadOnly method :
e.Cancel = IsReadOnly(e.Cell.Field.Name);
oh dear...that isn't very good...
I would also want to set the cell formatting of this (all editable cells to be pale yellow or something), but i guess you're saying that's not possible with the current grid?
Hello,
If you need conditional formatting as well, then you have to take another path. For example, you could create a style for the editor inside the CellValuePresenter and set its ReadOnly property. For example :
<local:IsReadOnlyConverter x:Key="conv"/>
<Style TargetType="{x:Type igEditors:XamTextEditor}">
<Setter Property="IsReadOnly" Value="{Binding Path=Host, RelativeSource={RelativeSource Self}, Converter={StaticResource conv}}"/>
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
Where the converter will return true/false value based on the condition. Please note that the binding targets the CellValuePresenter, which in the sample I created, I used to determine the row index and field index to determine the IsReadOnly Value:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
CellValuePresenter cvp = value as CellValuePresenter;
if (cvp != null)
return (cvp.Field.Index + cvp.Record.Index) % 2 == 0;
}
else
return Binding.DoNothing;
For more information on coditional formatting using converters, you can look at this blog post.