We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridDataControl - Making Cells ReadOnly based on bound value

Hi,

Is there a possibility to make cells read-only based on a value inside the business objects located in the ItemsSource?

<syncfusion:GridDataVisibleColumn Binding="{Binding IsSelected}" HeaderText="Selected"
AllowDrag="False" AllowGroup="False">
<syncfusion:GridDataVisibleColumn.ColumnStyle>
<syncfusion:GridDataColumnStyle CellType="CheckBox" HorizontalAlignment="Center" IsThreeState="False"
ReadOnly="{Binding IsEnabled}" />
</syncfusion:GridDataVisibleColumn.ColumnStyle>
<syncfusion:GridDataVisibleColumn.HeaderStyle>
<syncfusion:GridDataColumnStyle HorizontalAlignment="Center"/>
</syncfusion:GridDataVisibleColumn.HeaderStyle>
</syncfusion:GridDataVisibleColumn>

This idea fails due to that the ReadOnly property of the GridDataColumnStyle is no DependencyProperty...

Any ideas?

5 Replies

SM Saravanan M Syncfusion Team January 8, 2014 06:16 AM UTC

Hi Patrick,

Thank you for contacting Syncfusion support, 

We have analyzed your query. You can use IsReadOnly property in Visiblecolumn. Please refer the below code snippet to achieve your requirement.

Code snippet[C#]:

<syncfusion:GridDataVisibleColumn MappingName="Status" IsReadOnly="{Binding  Path=IsChecked,ElementName=checkbox}" AllowSort="False" HeaderText="Status">

We have prepared a sample based on your requirement and you can download it from below location,

 Sample Location: GridDataControl_checkbox_IsReadOnly.zip

Please let us know if this sample helps you,

 Regards,

Saravanan.M



PC Patrick Crucq January 8, 2014 09:01 AM UTC

Hi,

Thank you for your fast response.

Unfortunately, this scenario differs from mine. While in your example the CheckBox value prevents the whole column to be readonly, I need to have cell / row level granularity.

Another attempt to create the behavior I'am searching for was to use ConditionalFormats by adding an "invisible" VisibleColumn to the GridDataControl, because GridDataCondition offers no possibility to bind directly to the items in the ItemsSource.

While this works with such properties like Background and affects the whole row, I was not able to make the column cells readonly: 

<syncfusion:GridDataControl.ConditionalFormats>
<syncfusion:GridDataConditionalFormat>
<syncfusion:GridDataConditionalFormat.Style>
<syncfusion:GridDataStyleInfo Background="Red" />
</syncfusion:GridDataConditionalFormat.Style>
<syncfusion:GridDataConditionalFormat.Conditions>
<syncfusion:GridDataCondition ColumnName="IsReadOnly" PredicateType="And" ConditionType="Equals" Value="True"/>
</syncfusion:GridDataConditionalFormat.Conditions>
</syncfusion:GridDataConditionalFormat>

</syncfusion:GridDataControl.ConditionalFormats>
<syncfusion:GridDataControl.VisibleColumns>
<syncfusion:GridDataVisibleColumn Width="0" MaximumWidth="0"
AllowDrag="False" AllowFilter="False" AllowGroup="False" AllowResize="False" AllowSort="False"
Binding="{Binding IsReadOnly}" HeaderText="IsReadOnly"/>
<syncfusion:GridDataVisibleColumn Width="30"
AllowDrag="False" AllowFilter="False" AllowGroup="False" AllowResize="False" AllowSort="False"
Binding="{Binding IsSelected, Mode=TwoWay}" HeaderText=" ">
<syncfusion:GridDataVisibleColumn.ColumnStyle>
<syncfusion:GridDataColumnStyle CellType="CheckBox" HorizontalAlignment="Center" IsThreeState="False" />
</syncfusion:GridDataVisibleColumn.ColumnStyle>
</syncfusion:GridDataVisibleColumn>

I could live with an solution that affects the whole row because the CheckBox column is the only one that might be not readonly depending on the IsReadOnly value in the business objects.

Hope this clarifies my requirements.



SM Saravanan M Syncfusion Team January 9, 2014 07:37 AM UTC

Hi Patrick, 

Thanks for your update, 

Regarding Query1:

 We have analyzed your query. If you want to apply ReadOnly property for cell based on the business object (IsReadOnly), you need to hook QueryCellInfo event. Where you can set the ReadOnly property for cell based on your business object value. Please refer the below code snippet

Code snippet[C#]:

this.syncgrid.Model.QueryCellInfo += Model_QueryCellInfo;

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)

{

 .

 .

if ((bool)value)

{

 e.Style.GridModel[e.Style.RowIndex,e.Style.ColumnIndex].ReadOnly = true;

}

}

 

Regarding Query2:

If you don’t want to apply conditional format for whole row, you need to use ApplyStyleToColumn API. Please refer the below code snippet.

<syncfusion:GridDataControl.ConditionalFormats>

 <syncfusion:GridDataConditionalFormat  ApplyStyleToColumn="Status"> 

We have prepared a sample based on your requirements and you can download it from below location,

Sample Location: GridDataControl_checkbox_IsReadOnly_Modified.zip 

Please let us know if this sample helps you, 

Regards,

Saravanan.M



PC Patrick Crucq January 9, 2014 08:29 AM UTC

Great. 

Thank you for the solutions!

Best regards
Patrick


SM Saravanan M Syncfusion Team January 10, 2014 07:31 AM UTC

Hi Patrick,

Thank you for your update. Please let us know if you need further assistance.

Regards,

Saravanan.M


Loader.
Live Chat Icon For mobile
Up arrow icon