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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

sfDataGrid with "no data" information

Thread ID:

Created:

Updated:

Platform:

Replies:

125446 Aug 18,2016 04:49 PM UTC Aug 23,2016 06:23 AM UTC WPF 6
loading
Tags: SfDataGrid
Harald Betzler
Asked On August 18, 2016 04:49 PM UTC

Hi,

I want to achieve, that a sfDataGrid displays a (unbound) row with content "no data", if the ItemSource is empty.

Can you help?

Regards
Harald

Sowndaiyan Paulpandi [Syncfusion]
Replied On August 19, 2016 12:40 PM UTC

Hi Harald,

Thanks for contacting Syncfusion Support.

You can achieve your requirement by using the SfDataGrid.QueryUnBoundRow event like the below code example. Here you can able to set the UnboundRow value as per your requirement,

C#

 

    SfdataGrid.QueryUnBoundRow += SfdataGrid_QueryUnBoundRow;

 
    void SfdataGrid_QueryUnBoundRow(object sender, GridUnBoundRowEventsArgs e) 
        { 
            if ((this.SfdataGrid.DataContext as ViewModel).GDCSource.Count == 0) 
            { 
                e.Value = "No Data"; 
                e.Handled = true; 
            } 
        }

 

We have prepared a sample as per your requirement and you can download the same from the below location,

Sample : http://www.syncfusion.com/downloads/support/forum/125446/ze/WPF-515786354
 

Regards,
Sowndaiyan



Harald Betzler
Replied On August 21, 2016 02:21 PM UTC

Hi Sowndaiyan,

Thank you. It works. 

I think it would be better to use this.SfdataGrid.GetRecordsCount(false) instead of (this.SfdataGrid.DataContext as ViewModel).GDCSource.Count because there is no dependency to the ViewModel.

Are there any drawbacks?

Regards
Harald

Harald Betzler
Replied On August 21, 2016 04:42 PM UTC

Hi,

I've another problem after implementing the GridUnboundRow in combination with property AllowRowHoverHighlighting="True"

In run time it works as expected. But in design time I get a NullReferenceException until I remove the unbound row or switch AllowRowHoverHighlighting to False.


Regards
Harald

Sowndaiyan Paulpandi [Syncfusion]
Replied On August 22, 2016 09:11 AM UTC

Hi Harald,

Query [GetRecordsCount] : 

In SfDataGrid , the View.Records.Count will be affected when we apply the filtering. So using GetRecordsCount method is not an optimal way to find the ItemSource count. So we recommend you to use any of the below solutions,  
 

Solution 1 :

   var ch = (this.SfdataGrid.DataContext as ViewModel).GDCSource.Count;

Solution 2 :

   
var ch1 = (this.SfdataGrid.View.SourceCollection as IList).Count;  
 
   
 
Query [NullReferenceException] :

We have created the support incident under your account to track the status of this requirement. Please log on to our support website to check for further updates.  
 

Regards,
Sowndaiyan 
 
 


Harald Betzler
Replied On August 22, 2016 03:31 PM UTC

Hi Sowndaiyan,

thank you for creating an issue due to the NullReferenceException.

And thank you for the hint with the potentially "filtered" result for SfDataGrid.GetRecordsCount(false).

I think solution 2 will make the race, because I don't need a reference to the ViewModel.

Regards
Harald

Sowndaiyan Paulpandi [Syncfusion]
Replied On August 23, 2016 06:23 AM UTC

Hi Harald,

Thanks for the update.

Please let us know if you need further assistance.

Regards,
Sowndaiyan
 


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.

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

;