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

Display count of details on master row

Thread ID:





148519 Oct 23,2019 12:24 PM UTC Oct 25,2019 05:08 AM UTC WinForms 4
Tags: SfDataGrid
Costas Kounadis
Asked On October 23, 2019 12:24 PM UTC

I have a SfDataGrid master detail 
I want to display on master row in a cell , count of its details rows

Gowtham Gopalsamy [Syncfusion]
Replied On October 24, 2019 09:57 AM UTC

Hi Costas   
Thank you for using Syncfusion controls.   
You can achieve your requirement  “to display the detail view row count in master detail view column” by using GridUnboundColumn and you can set the cell value for the GridUnboundColumn by using  QueryUnboundColumnInfo event .   
 Please find the below code snippet.  
this.sfDataGrid1.Columns.Add(new GridUnboundColumn() { MappingName ="DisplayCount", HeaderText = "Display Count" });   
this.sfDataGrid1.QueryUnboundColumnInfo += SfDataGrid1_QueryUnboundColumnInfo;   
private void SfDataGrid1_QueryUnboundColumnInfo(object sender, Syncfusion.WinForms.DataGrid.Events.QueryUnboundColumnInfoArgs e)   
    var index = this.sfDataGrid1.TableControl.ResolveToRowIndex(e.Record);   
    if (e.UnboundAction == UnboundActions.QueryData)   
        var detailsViewDataGrid = SelectionHelper.GetDetailsViewGrid(this.sfDataGrid1, index + 1);   
        if (detailsViewDataGrid != null)   
            var count = detailsViewDataGrid.RowCount;   
            if (count != 1)   
                e.Value = count.ToString();   
                e.Value = 0;   
           e.Value = 0;   
Please find the below sample link.  
Please let us know, if you require further assistance on this.   

Costas Kounadis
Replied On October 24, 2019 10:35 AM UTC

Thanks for your answer 
Return wrong number of detail lines ( i have 3 and returns 8 !!!)

Costas Kounadis
Replied On October 24, 2019 11:33 AM UTC

Ok found solution base on that you send me
I took the value of the field associated with the detail and using linq count the detail lines

private void SfDataGrid1_QueryUnboundColumnInfo(object sender, Syncfusion.WinForms.DataGrid.Events.QueryUnboundColumnInfoArgs e)
            string cellValue;
            var index = sfDataGrid1.TableControl.ResolveToRowIndex(e.Record);
            var recordIndex = sfDataGrid1.TableControl.ResolveToRecordIndex(index);
            var record1 = sfDataGrid1.View.Records.GetItemAt(recordIndex);
            int columnIndex = sfDataGrid1.TableControl.ResolveToGridVisibleColumnIndex(1);
            var mappingName = sfDataGrid1.Columns[columnIndex].MappingName;
            cellValue = (record1.GetType().GetProperty(mappingName).GetValue(record1, null).ToString());
            BookingClassesDataContext Booking = new BookingClassesDataContext();
            int rec= Booking.bkRouteSchDetails.Where(x => x.ROUTESCHID == Int32.Parse(cellValue)).Count();
            if (e.UnboundAction == UnboundActions.QueryData)
                var detailsViewDataGrid = SelectionHelper.GetDetailsViewGrid(sfDataGrid1, index + 1);
                if (detailsViewDataGrid != null)
                    var count = rec;
                    if (count != 0)
                        e.Value = count;
                        e.Value = 0;
                    e.Value = 0;

Farjana Parveen Ayubb [Syncfusion]
Replied On October 25, 2019 05:08 AM UTC

Hi Costas 
Thanks for the update. 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
Farjana Parveen A 


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