Display count of details on master row
Hello
I have a SfDataGrid master detail
I want to display on master row in a cell , count of its details rows
SIGN IN To post a reply.
4 Replies
GG
Gowtham Gopalsamy
Syncfusion Team
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();
else
e.Value = 0;
}
else
e.Value = 0;
}
} |
Please find the below sample link.
Please let us know, if you require further assistance on this.
Regards,
Gowtham.
CK
Costas Kounadis
October 24, 2019 10:35 AM UTC
Thanks for your answer
Return wrong number of detail lines ( i have 3 and returns 8 !!!)
CK
Costas Kounadis
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;
else
e.Value = 0;
}
else
e.Value = 0;
}
}
FP
Farjana Parveen Ayubb
Syncfusion Team
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.
Regards,
Farjana Parveen A
SIGN IN To post a reply.
- 4 Replies
- 3 Participants
-
CK Costas Kounadis
- Oct 23, 2019 12:24 PM UTC
- Oct 25, 2019 05:08 AM UTC