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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Message not found

Thread ID:

Created:

Updated:

Platform:

Replies:

146974 Aug 27,2019 10:29 AM UTC Aug 28,2019 02:53 PM UTC WPF 1
loading
Tags: SfDataGrid
Tech Shop
Asked On August 27, 2019 10:29 AM UTC

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

Susmitha Sundar [Syncfusion]
Replied On 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
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon