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

Setting GridColumn.AllowEditingProperty user setter in code-behind is not setting the IsEnabled property in SfDataGrid.

Hi,

I have a DataTrigger which needs to set the AllowEditingProperty for the GridColumn (to be more specific individual GridCell) in code-behind. But it doesn't seem to work.
Here is what i am doing:
a. create a style and add a data trigger to it.
Style cellStyle = new Style();
DataTrigger isEnabledDataTrigger = new DataTrigger();
isEnabledDataTrigger.Binding = new Binding("IsEnabled");
isEnabledDataTrigger.Value = "False";
isEnabledDataTrigger.Setters.Add(new Setter(GridColumn.AllowEditingProperty, false));

b. Assign it to GridColumn
 GridComboBoxColumn gridComboBoxColumn = new GridComboBoxColumn(){MappingName="Name" CellStyle = cellStyle};

This is how I am setting the cell background and it works for me. But setting IsEnabled property doesn't work.

Thanks,
Om
 

9 Replies

OT Om Thapa January 22, 2014 06:18 PM UTC

Hi,

I was able to get the behavior I desired by replacing GridColumn.AllowEditingProperty as dependency property in setter with GridCell.IsEnabledProperty. However, when I click on disable cell, it doesn't select the row nor does it fire the selection changed event.

Thanks,
Om



JG Jai Ganesh S Syncfusion Team January 30, 2014 09:15 AM UTC

Hi Om,

 

Thank you for using Syncfusion products.

 

We have analyzed your query. In our Grid, we perform the Selection operation through GridCell events. We are unable to get any events if IsEnabled property is set to false, so the issue has occurred. Could you please let us know the detailed requirement for in what purpose you would like to use this behavior?  This would be more helpful for us to serve you.

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S



OT Om Thapa January 30, 2014 11:05 PM UTC

Jai,

In our application, there are times when we don't want user to modify the grid cell  in some row that is in some column depending on user privilege. We can't simply disable entire column by setting AllowEditing property to false because their might be grid cell in some row that user might be able to modify. As i mentioned in the previous post, I was able to disable the individual GridCell in any column by setting dependency property GridCell.IsEnabled using datatrigger. The problem then was it didn't select the row if used end up clicking on disabled gridcell. Right now as a workaround I have registered to listen for PreviewMouseLeftButtonDown event, when I receive this event, I get the datacontext from event's OriginalSource and add it to the SelectedItem list of a grid. But this doesn't handle the multi-select scenarios ( Shift + selection or Alt+ selection).

Thanks,
Om


JG Jai Ganesh S Syncfusion Team February 13, 2014 09:02 AM UTC

Hi Om,

 

Thank you for your update.

 

We have analysed your query. We are unable to get any events in the case “IsEnabled”  property is set to false. However you can achieve your requirement by using CurrentCellBeginEdit. This Event is fired when the current cell begins to enter into Edit Mode. In that if set the cancel property as true, the event will be cancelled and the current cell will not enter edit mode.  We have prepared the sample based on this and please find the sample under the following location,

 

Sample: SfDataGridEditingSample.zip

 

Note: In this sample we have disabled the editing for the EmployeeName Nancy.

Please let us know if you need further assistance.

Thank you,

Jai Ganesh S



OT Om Thapa March 24, 2014 10:01 PM UTC

Hi,

If I take an approach to cancel the CurrentCellBeginEdit event to disable editing, it only works for cell type: text box. It doesn't work for check box. User can directly change the value of check box, but event handler will never receive the CurrentCellBeginEdit event. The only time event handler can receive this even is when user clicks on the white space in the check box column. But for users it makes no sense to click on the white space when they are changing the value of check box.

The behavior I want is very similar to if I were to set AllowEditing to false for a column but I need to be able to do it for each column. When I set AllowEditing for a check box, it disables the checkbox column, but I am still able to make a selection and receive a SelectionChangedEvent. May be I could achieve the result I want, if you can tell me how it is being done for a column. 

Thanks,
Om


JS Jayapradha S Syncfusion Team April 11, 2014 06:29 AM UTC

Hi Om,

 

We apologize for the delay caused.

 

You can disable the edit mode for checkbox also based on the value of textbox by using GridTemplateColumn and IDataErrorInfo interface.

Find the code snippet below,

 

Code Snippet:

public string Error

{

get { return ""; }

}

public string this[string columnName]

{

get

{

if (columnName == "EmployeeName")

{

if (this.EmployeeName == "Nancy")

{

this.IsEnabled = false;

}

}

return "";

}

}

 

Xaml Code:

 

<syncfusion:GridTemplateColumn MappingName="Check">

<syncfusion:GridTemplateColumn.CellTemplate>

<DataTemplate>

<CheckBox  IsEnabled="{Binding Path=IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"IsThreeState="False" />

</DataTemplate>

</syncfusion:GridTemplateColumn.CellTemplate>                

</syncfusion:GridTemplateColumn>    

 

Please Refer the below attached sample.

 

Kindly let us know if this solution helps you.

 

Regards,

Jayapradha


Attachment: SfGridSample_f6dfeab5.zip


JS Jayapradha S Syncfusion Team April 11, 2014 08:20 AM UTC

Hi Om,

 

Alternative way to achieve your desired requirement by using Converter without using an any additional property. Find the code snippet below,

 

Code Snippet:

<syncfusion:GridTemplateColumn.CellTemplate>

<DataTemplate>

<Grid HorizontalAlignment="Center" VerticalAlignment="Center">

<CheckBox IsChecked="{Binding Path=Check,

                              Mode=TwoWay,

                              UpdateSourceTrigger=PropertyChanged}"

                              IsEnabled="{Binding Path=EmployeeName,

                              Converter={StaticResource checkBoxEditBehaviorConverter}}"

                              IsThreeState="False" />

</Grid>

</DataTemplate>

</syncfusion:GridTemplateColumn.CellTemplate>

 

Please Refer the below attached sample.

 

 

 

Regards,

Jayapradha


Attachment: SfGridSample_7ae0ac6c.zip


OT Om Thapa April 14, 2014 04:31 PM UTC

Jayapradha,

The solution you provided worked for me. I was trying to download the SfDataGridEditingSample.zip sample solution provided by Jai Ganesh but it seems link is broken. Can you please update the link.

Thanks,
Om


JS Jayapradha S Syncfusion Team April 15, 2014 05:05 PM UTC

Hi Om,

 

Thanks for your update.

 

Find the required attached sample.

 

Please let us know if you have any queries.

 

Regards,

Jayapradha


Attachment: SfDataGridEditingSample_82656f22.zip

Loader.
Live Chat Icon For mobile
Up arrow icon