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

sfDataGrid with "no data" information

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

6 Replies

SP Sowndaiyan Paulpandi Syncfusion Team 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 : https://www.syncfusion.com/downloads/support/forum/125446/ze/WPF-515786354
 

Regards,
Sowndaiyan




HB Harald Betzler 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


HB Harald Betzler 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


SP Sowndaiyan Paulpandi Syncfusion Team 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 
 
 



HB Harald Betzler 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


SP Sowndaiyan Paulpandi Syncfusion Team August 23, 2016 06:23 AM UTC

Hi Harald,

Thanks for the update.

Please let us know if you need further assistance.

Regards,
Sowndaiyan
 


Loader.
Live Chat Icon For mobile
Up arrow icon