Message not found
How to include a message of items not found in SfDataGrid for WPF and keep the grid header?
SIGN IN To post a reply.
1 Reply
SS
Susmitha Sundar
Syncfusion Team
August 28, 2019 02:53 PM UTC
Hi Tech,
Thank you for contacting Syncfusion support.
Based on the provided information, your requirement of “Show Message of Items not found in SfDataGrid” can be achieved using the UnBoundRows property of SfDataGrid.
Please refer the following code example for the same,
C#:
|
public class DataNotFoundBehavior:Behavior<SfDataGrid>
{
protected override void OnAttached()
{
this.AssociatedObject.Loaded += AssociatedObject_Loaded;
}
private void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
if (this.AssociatedObject.View.Records.Count <= 0)
{
this.AssociatedObject.UnBoundRows.Add(new GridUnBoundRow() { Position = UnBoundRowsPosition.Top });
this.AssociatedObject.UnBoundRowCellStyle = Application.Current.MainWindow.Resources["style"] as Style;
this.AssociatedObject.QueryRowHeight += AssociatedObject_QueryRowHeight;
this.AssociatedObject.QueryUnBoundRow += AssociatedObject_QueryUnBoundRow;
this.AssociatedObject.QueryCoveredRange += AssociatedObject_QueryCoveredRange;
}
}
private void AssociatedObject_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
{
var unboundRow = this.AssociatedObject.GetUnBoundRow(e.RowColumnIndex.RowIndex);
if (unboundRow == null)
return;
else if (e.RowColumnIndex.ColumnIndex == 0)
{
e.Range = new CoveredCellInfo(e.RowColumnIndex.ColumnIndex, (e.OriginalSender as SfDataGrid).Columns.Count, e.RowColumnIndex.RowIndex, e.RowColumnIndex.RowIndex);
e.Handled = true;
}
}
private void AssociatedObject_QueryUnBoundRow(object sender, GridUnBoundRowEventsArgs e)
{
if (e.RowColumnIndex.ColumnIndex == 0)
{
e.Value = "Items not found";
e.Handled = true;
}
}
private void AssociatedObject_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (AssociatedObject.IsUnBoundRow(e.RowIndex))
{
e.Height = 150;
e.Handled = true;
}
}
} |
We have prepared sample based on your requirement, please find the sample by the following link.
Sample link: https://www.syncfusion.com/downloads/support/forum/146974/ze/SfDataGridDemo_DataNotFound-657783502
We hope this helps. Please let us know, if need any further assistance.
Regards,
Susmitha S
Susmitha S
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
TS Tech Shop
- Aug 27, 2019 10:29 AM UTC
- Aug 28, 2019 02:53 PM UTC