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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

115568 Jan 22,2014 12:27 PM Apr 15,2014 01:05 PM WPF 9
loading
Tags: GridControl
Om Thapa
Asked On January 22, 2014 12:27 PM

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
 

Om Thapa
Replied On January 22, 2014 01:18 PM

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


Jai Ganesh S [Syncfusion]
Replied On January 30, 2014 04:15 AM

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


Om Thapa
Replied On January 30, 2014 06:05 PM

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

Jai Ganesh S [Syncfusion]
Replied On February 13, 2014 04:02 AM

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


Om Thapa
Replied On March 24, 2014 06:01 PM

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

Jayapradha S [Syncfusion]
Replied On April 11, 2014 02:29 AM

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

Jayapradha S [Syncfusion]
Replied On April 11, 2014 04:20 AM

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

Om Thapa
Replied On April 14, 2014 12:31 PM

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

Jayapradha S [Syncfusion]
Replied On April 15, 2014 01:05 PM

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

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.

;