Hide/Collapse SfDataGrid Columns

Hello,

in a SfDataGrid column I should display one of two types of values, either a numeric one (float) or a boolean one. The one which should be shown (and edited) has a value != null (NOT NULL). I tried this with the IsHidden property (depending on the null value), but this is not working. Always the last defined column (of the 2) is shown (the GridNumericColumn in the snippet).

syncfusion:GridCheckBoxColumn
  MappingName="ValueBoolean"
  IsHidden={Binding
ValueBoolean, Source=Source={StaticResource cvsData}, Converter={StaticResource ConverterNull2Hidden}}"

syncfusion:GridNumericColumn
  MappingName="ValueNumeric"
  IsHidden={Binding
ValueNumeric, Source=Source={StaticResource cvsData}, Converter={StaticResource ConverterNull2Hidden}}"

Could You give me an advise how to do this?


3 Replies

JG Jai Ganesh S Syncfusion Team April 9, 2018 11:36 AM UTC

Hi Thomas, 
 
We suspect that, you want to hide the cells in SfDataGrid column based on null value. We regret to inform you that, we cannot hide the particular cell in SfDataGrid. However, you can skip the editing for the null value cells by using the below code, 
 
public class EditBehavior : Behavior<SfDataGrid> 
    { 
        protected override void OnAttached() 
        { 
            base.OnAttached(); 
            this.AssociatedObject.CurrentCellBeginEdit += AssociatedObject_CurrentCellBeginEdit; 
        } 
 
        private void AssociatedObject_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs e) 
        { 
            var propertyAccessProvider = this.AssociatedObject.View.GetPropertyAccessProvider(); 
            var newValue = propertyAccessProvider.GetValue(this.AssociatedObject.CurrentItem, this.AssociatedObject.CurrentColumn.MappingName); 
 
            if(newValue==null) 
            { 
                e.Cancel = true; 
            } 
        } 
    } 
 
 
The below KB describes to disable the edit mode based on the AllowEditing property in AddNewRow, 
KB Link: 
 
You can also show the error values using for null values in a column using cell validation and please find the UG link from below, 
 
If the above solution is not meet your requirement then please share the more information about your query or please replicate the issue in simple sample? This would be more helpful for us to proceed further. 
 
Regards, 
Jai Ganesh S


TS Thomas Schmid April 22, 2018 04:16 PM UTC

Hi Jai,

I have managed to solve the problem with ordinary WPF tools. But nevertheless, does "IsHidden" correspond to the WPF Visibility.Hidden or Visibility.Collapsed?

Best regards
Thomas


JG Jai Ganesh S Syncfusion Team April 23, 2018 07:03 AM UTC

Hi Thomas, 
Thanks for the feedback. IsHidden property name taken based on Visibility.Hidden. Collapsed option not provided since column can be removed from DataGrid.Columns collection.  
Documentation References: 
 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon