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.
Unfortunately, activation email could not send to your email. Please try again.

GridDataControl - Making Cells ReadOnly based on bound value

Thread ID:

Created:

Updated:

Platform:

Replies:

115248 Jan 7,2014 05:59 AM Jan 10,2014 02:31 AM WPF 5
loading
Tags: GridControl
Patrick Crucq
Asked On January 7, 2014 05:59 AM

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?

Saravanan M [Syncfusion]
Replied On January 8, 2014 01:16 AM

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


Patrick Crucq
Replied On January 8, 2014 04:01 AM

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.


Saravanan M [Syncfusion]
Replied On January 9, 2014 02:37 AM

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


Patrick Crucq
Replied On January 9, 2014 03:29 AM

Great. 

Thank you for the solutions!

Best regards
Patrick

Saravanan M [Syncfusion]
Replied On January 10, 2014 02:31 AM

Hi Patrick,

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

Regards,

Saravanan.M


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;