Bind grid row visibility to model property
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?
SIGN IN To post a reply.
5 Replies
MA
Mohanram Anbukkarasu
Syncfusion Team
October 25, 2021 03:14 PM UTC
Hi Chris,
Thanks for contacting Syncfusion products.
You can achieve your requirement to hide the rows in the SfDataGrid based on the underlying Boolean object by handling the QueryRowHeight event and setting row height for as Zero as shown below.
Code example :
|
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;
}
} |
Please let us know if you require any other assistance from us.
Regards,
Mohanram A.
CB
Chris Bentley
October 25, 2021 03:43 PM UTC
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.
MA
Mohanram Anbukkarasu
Syncfusion Team
October 26, 2021 10:18 AM UTC
Hi Chris,
Thanks for the update.
You can resolve this by handling the SfDataGrid.View.RecordPropertyChanged event and reset the row heights as shown in the following code example.
Code example :
|
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;
}
}
|
Sample link : https://www.syncfusion.com/downloads/support/forum/169866/ze/SfDataGrid_Demo_Modified-688050868
Please let us know if you require any other assistance from us.
Regards,
Mohanram A.
CB
Chris Bentley
October 26, 2021 12:17 PM UTC
This works, thank you.
MA
Mohanram Anbukkarasu
Syncfusion Team
October 27, 2021 05:00 AM UTC
Hi Chris,
Thanks for the update.
We are glad to know that the provided solution worked at your end. Please let us know if you require any other assistance from us. We are happy to help you.
Regards,
Mohanram A.
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
CB Chris Bentley
- Oct 22, 2021 06:54 PM UTC
- Oct 27, 2021 05:00 AM UTC