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

Data binding

Hi,

I just want to bind the AllowEditing of the SfDataGrid to the Mapping value "CheckIn". The below AllowEditing binding is not working. Does anyone know how to do it.

 <my:SfDataPager x:Name="sfDataPager" PageSize="3" Source="{Binding List}"/>

<syncfusion:SfDataGrid x:Name="datagrid" ItemsSource="{Binding PagedSource,ElementName=sfDataPager}" >
            <syncfusion:SfDataGrid.Columns>
                <syncfusion:GridCheckBoxColumn AllowEditing="{Binding DataContext.CheckIn}"  MappingName="CheckIn" />             
            </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

Thanks,
Ryn

3 Replies

JG Jai Ganesh S Syncfusion Team October 13, 2016 01:27 PM UTC

Hi Benia, 
 
We have analyzed your query. We regret to inform you that you can not bind GridCheckBoxColumn’s AllowEditing based on the underlying property but you can disable the cell based on the underlying property like below, 
 
<syncfusion:GridCheckBoxColumn MappingName="IsChecked" > 
                    <syncfusion:GridCheckBoxColumn.CellStyle> 
                        <Style TargetType="syncfusion:GridCell"> 
                            <Setter Property="utils:SetterValueBindingHelper.PropertyBinding"> 
                                <Setter.Value> 
                                     <utils:SetterValueBindingHelper Property="IsEnabled"  Binding="{Binding Converter={StaticResource converter}}"/> 
                                </Setter.Value> 
                            </Setter> 
                        </Style> 
                    </syncfusion:GridCheckBoxColumn.CellStyle> 
 </syncfusion:GridCheckBoxColumn> 
 
public class customconverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, string language) 
        { 
           return (value as UserInfo).IsChecked; 
        } 
 
        public object ConvertBack(object value, Type targetType, object parameter, string language) 
        { 
            return (value as UserInfo).IsChecked; 
        } 
    } 
 
 
Screen Shot: 
 
 
 
Regards, 
Jai Ganesh S 



MA Muhammed Ali Sheikh February 16, 2022 05:04 PM UTC

Hi Jai Ganesh,

I want the same solution in UWP sfdatagrid. Based on some condition I have to disable some items and let few items enabled. Even though in ObservableCollection I'm disabling few of them but the NotifyPropertyChanged isn't firing. Only upon scrolling the collection is getting updated in the grid.



VS Vijayarasan Sivanandham Syncfusion Team February 17, 2022 11:17 AM UTC

Hi Muhammed Ali Sheikh,

Your requirement can be achieved by using CellStyleSelector property and CurrentCellEndEdit event in SfDataGrid. Please refer the below code snippet, 
 
XAML Code Snippet: 
<Application.Resources> 
        <local:SelectorClass x:Key="styleSelector"/> 
        <Style x:Key="disableCell" TargetType="syncfusion:GridCell"> 
            <Setter Property="IsEnabled" Value="True" /> 
        </Style> 
        <Style x:Key="enableCell" TargetType="syncfusion:GridCell"> 
            <Setter Property="IsEnabled" Value="False" /> 
        </Style> 
</Application.Resources> 
 
<syncfusion:SfDataGrid x:Name="sfGrid" 
                                   Grid.Row="1" 
                                   ColumnSizer="Star" 
                                   AllowEditing="True" 
                                   AutoGenerateColumns="False" 
                                   GridValidationMode="InView" 
                                   CellStyleSelector="{StaticResource styleSelector}" 
                                   LiveDataUpdateMode="AllowDataShaping" 
                                   ItemsSource="{Binding UserDetails}" 
                                   ShowRowHeader="True"/> 
 
C# Code Snippet for update the CellStyle at runtime: 
 
this.sfGrid.CurrentCellEndEdit += OnCurrentCellEndEdit; 
 
private void OnCurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e) 
{ 
            //Change the CellStyle at runtime by update the value changed row index in SfDataGrid 
            this.sfGrid.UpdateDataRow(e.RowColumnIndex.RowIndex); 
} 
 
C# Code Snippet for Style Selector: 
 
public class SelectorClass : StyleSelector 
{ 
        protected override Style SelectStyleCore(object item, DependencyObject container) 
        { 
            var data = item as UserInfo; 
 
            //here customize based on your scenario 
            if (data != null && ((container as GridCell).ColumnBase.GridColumn.MappingName == "IsChecked")) 
            { 
                //custom condition is checked based on data. 
                if (data.UserId > 10005) 
                    return App.Current.Resources["disableCell"] as Style; 
                return App.Current.Resources["enableCell"] as Style; 
            } 
            return base.SelectStyleCore(item, container); 
        } 
} 
 
Sample Link: https://www.syncfusion.com/downloads/support/forum/126380/ze/SfDataGridDemo1204985064

For more information related to Conditional styling of cells using style selector, please refer the below user guide documentation link, 

Regards, 
Vijayarasan S 


Loader.
Live Chat Icon For mobile
Up arrow icon