The grid's ItemSource is bound to a collection of objects. Each object has a bool property IsDeleted. I can't remove the items from the collection until the user commits, but I don't want them to be visible in the grid when IsDeleted is true. Can I bind row visibility to the IsDeleted property?
|
private void OnDataGrid_QueryRowHeight(object sender, Syncfusion.UI.Xaml.Grid.QueryRowHeightEventArgs e)
{
var record = this.dataGrid.RowGenerator.Items.FirstOrDefault(x => x.RowType == Syncfusion.UI.Xaml.Grid.RowType.DefaultRow && x.RowIndex == e.RowIndex);
if(record != null && (record.RowData as EmployeeInfo).IsDeleted)
{
e.Height = 0;
e.Handled = true;
}
} |
This seems like it would work if IsDeleted was already set to True when the grid binds. But, this property, which does generate PropertyChanged events, is set after the grid is loaded when the user clicks a delete button. When the property is set to True, the QueryRowHeight event is not fired, so the row stays visible.
|
this.dataGrid.Loaded += OnDataGrid_Loaded;
private void OnDataGrid_Loaded(object sender, RoutedEventArgs e)
{
this.dataGrid.View.RecordPropertyChanged += OnRecordPropertyChanged;
}
private void OnRecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
this.dataGrid.GetVisualContainer().RowHeightManager.Reset();
dataGrid.GetVisualContainer().InvalidateMeasureInfo();
}
private void OnDataGrid_QueryRowHeight(object sender, Syncfusion.UI.Xaml.Grid.QueryRowHeightEventArgs e)
{
var record = this.dataGrid.RowGenerator.Items.FirstOrDefault(x => x.RowType == Syncfusion.UI.Xaml.Grid.RowType.DefaultRow && x.RowIndex == e.RowIndex);
if(record != null && (record.RowData as EmployeeInfo).IsDeleted)
{
e.Height = 0;
e.Handled = true;
}
}
|
This works, thank you.