We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Message not found

How to include a message of items not found in SfDataGrid for WPF and keep the grid header?

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. 
 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Susmitha S
 


Loader.
Up arrow icon