Hide specific columns SfDataGrid and conditional formatting cells based on values

Hello,

I am working with XAML and .Net core to develop an application but i have some difficulties in implementing conditional formatting and hiding some columns in sfdatagrid.

I appreciate any help.


BR


1 Reply

BT Balamurugan Thirumalaikumar Syncfusion Team September 24, 2021 06:04 AM UTC

Hi Flavius, 

Thank you for interesting in Syncfusion products. 

We have checked your query “Hide specific columns SfDataGrid and conditional formatting cells based on values” at our end. In order to achieve your requirement in SfDataGrid .NetCore project, we have prepared the simple sample. You can refer the following sample and code snippet for your reference.  

Code Snippets 
<Window.DataContext> 
    <local:ViewModel /> 
</Window.DataContext> 
<Window.Resources> 
    <local:ColorConverter x:Key="converter"/> 
    <Style TargetType="syncfusion:VirtualizingCellsControl"> 
        <Setter Property="Background" Value="{Binding Converter={StaticResource converter}}" /> 
    </Style> 
</Window.Resources> 
<Grid> 
    <syncfusion:SfDataGrid x:Name="dataGrid"  ItemsSource="{Binding Orders}"  > 
        <syncfusion:SfDataGrid.Columns> 
            <syncfusion:GridTextColumn IsHidden="True" MappingName="Country"/> 
        </syncfusion:SfDataGrid.Columns> 
    </syncfusion:SfDataGrid> 
</Grid> 
 
public class ColorConverter : IValueConverter 
{ 
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    var input = (value as OrderInfo).OrderID; 
 
    //custom condition is checked based on data. 
    if (input < 1003) 
        return new SolidColorBrush(Colors.Bisque); 
 
    else if (input < 1007) 
        return new SolidColorBrush(Colors.LightBlue); 
 
    else if (input >= 1007) 
        return new SolidColorBrush(Colors.Yellow); 
 
    else 
        return DependencyProperty.UnsetValue; 
 
} 
 
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    throw new NotImplementedException(); 
} 
} 


Also you can refer the following documentation for your reference. 



Please let us know if you would require any other assistance. we will be always happy to assist you. 

Thanks & Regards, 
Balamurugan Thirumalaikumar  


Loader.
Up arrow icon