Hide Column binding bool from View Model

Hello,

I have a problem with the DataGrid, currently I tried to hide an specific column with this

<syncfusion:GridTemplateColumn IsHidden="{Binding Path=BindingContext.HideID, Source={x:Reference rootView}}" MappingName="DesgloseID">

But the column is still visible, I already tried change it to

<syncfusion:GridTemplateColumn IsHidden="{Binding HideID}" MappingName="DesgloseID">

and

<syncfusion:GridTemplateColumn IsHidden="{Binding Path=HideID}" MappingName="DesgloseID">

HideID is a public bool property in my ViewModel with PropertyChanged

3 Replies

SS Sivaraman Sivagurunathan Syncfusion Team February 7, 2018 04:50 PM UTC

Hi Juan, 
 
Thanks for using Syncfusion support.  
 
We have checked your query. you can achieve your requirement by using IsHidden property. We have prepared the sample based on your requirement and  attach the sample for your reference you can download the same from the below link. 
 
 
 
<syncfusion:SfDataGrid x:Name="dataGrid" 
                    AllowEditing="True" 
                    ItemsSource="{Binding OrdersInfo}" 
                    ColumnSizer="Star" 
                    AutoGenerateColumns="False"> 
<syncfusion:SfDataGrid.Columns> 
<syncfusion:GridTextColumn MappingName="ShipCountry" IsHidden="{Binding IsHide, Source={x:Reference viewModel}}"/> 
<syncfusion:GridTextColumn MappingName="OrderID"  /> 
<syncfusion:GridTextColumn MappingName="CustomerID" /> 
<syncfusion:GridTextColumn MappingName="FirstName" /> 
</syncfusion:SfDataGrid.Columns> 
</syncfusion:SfDataGrid> 
 
// View Model 
private bool isHide = true; 
 
public bool IsHide 
{ 
    get { return isHide; } 
    set { 
        this.isHide = value; 
        RaisePropertyChanged("IsHide"); 
    } 
} 
 
 
Regards, 
Sivaraman 



JC Juan Carlos Gonzalez Salazar February 7, 2018 05:17 PM UTC

Hello Sivaraman,

Is there an alternative? Because I can't create an instance of the ViewModel like that.


SS Sivaraman Sivagurunathan Syncfusion Team February 8, 2018 01:42 PM UTC

Hi Juan, 
 
We have checked your query. If you are unable to create a instance in Xaml page, you can create the instance of ViewModel in code behind. We have prepared the sample based on your requirement and attached for your reference you can download the same from the below link. 
 
 
 
// Code Behind 
ViewModel viewModel; 
public MainPage() 
{ 
    InitializeComponent(); 
    viewModel = new ViewModel(); 
    this.BindingContext = viewModel; 
    dataGrid.Columns[0].SetBinding(GridColumn.IsHiddenProperty, new Binding() { Path= "IsHide", Source = viewModel }); 
} 
 
 
 
Regards, 
Sivaraman  


Loader.
Up arrow icon