Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
141048 | Nov 20,2018 12:56 PM UTC | Nov 23,2018 04:13 AM UTC | WinForms | 7 |
![]() |
Tags: GridGroupingControl |
this.gridGroupingControl1.TableControlCellClick += GridGroupingControl1_TableControlCellClick;
private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e)
{
if (e.TableControl.CurrentCell.MoveFromColIndex == e.TableControl.CurrentCell.ColIndex)
return;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
if (style.CellValueType == typeof(int))
{
if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null)
{
string columnName = style.TableCellIdentity.Column.Name;
if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count > 0)
//Clear the previous summary rows to add the
this.gridGroupingControl1.TableDescriptor.SummaryRows.Clear();
GridSummaryColumnDescriptor scd = new GridSummaryColumnDescriptor();
scd.SummaryType = Syncfusion.Grouping.SummaryType.Int32Aggregate;
scd.Format = "{Sum}";
scd.DataMember = columnName;
scd.Name = "SumOf" + columnName;
GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor("Row1", scd);
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd);
//To update the summary.
this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors();
}
}
} |
Hi Gregory,
Thanks for using Syncfusion product.
To add the summary while click on the column, you could use the GridTableCellStyleInfo and SummaryRows in TableControlCellClick event. Please refer the following code example,
Code example
this.gridGroupingControl1.TableControlCellClick += GridGroupingControl1_TableControlCellClick;private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e){if (e.TableControl.CurrentCell.MoveFromColIndex == e.TableControl.CurrentCell.ColIndex)return;GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);if (style.CellValueType == typeof(int)){if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null){string columnName = style.TableCellIdentity.Column.Name;if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count > 0)//Clear the previous summary rows to add thethis.gridGroupingControl1.TableDescriptor.SummaryRows.Clear();GridSummaryColumnDescriptor scd = new GridSummaryColumnDescriptor();scd.SummaryType = Syncfusion.Grouping.SummaryType.Int32Aggregate;scd.Format = "{Sum}";scd.DataMember = columnName;scd.Name = "SumOf" + columnName;GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor("Row1", scd);this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd);//To update the summary.this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors();}}}
Arulraj A
Query |
Response |
after clicking the next column, GridSummaryColumnDescripto did not disappear
so that the second, third |
To add the new column, you could create the GridsummaryColumnDescriptor for that column the add this summary column in SummaryRows collection. If want to remove the column from summary columns when click on the same column, you could check and remove that column from SummaryColumns collection. Please refer the following code example
Code example
private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
if (style.CellValueType == typeof(int))
{
if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null)
{
string columnName = style.TableCellIdentity.Column.Name;
GridSummaryColumnDescriptor scd = null;
if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count == 0)
{
scd = AddSummaryColumn(columnName);
GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor();
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd);
}
GridSummaryRowDescriptor summaryRow = this.gridGroupingControl1.TableDescriptor.SummaryRows[0];
var summarycolDescriptor = summaryRow.SummaryColumns.Cast<GridSummaryColumnDescriptor>().Where(x => x.DataMember == columnName);
if (summarycolDescriptor.Count() > 0)
{
var value = summarycolDescriptor.ToList()[0];
summaryRow.SummaryColumns.Remove(value);
}
else
{
scd = AddSummaryColumn(columnName);
summaryRow.SummaryColumns.Add(scd);
}
//To update the summary.
this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors();
}
}
} |
when we click the second time in the same column - it should disappear only in what we clicked a second time
- when we click the third time it adds again |
Hi Gregory,
Thanks for your update.
Query Response
after clicking the next column, GridSummaryColumnDescripto did not disappear
so that the second, third
To add the new column, you could create the GridsummaryColumnDescriptor for that column the add this summary column in SummaryRows collection. If want to remove the column from summary columns when click on the same column, you could check and remove that column from SummaryColumns collection. Please refer the following code example
Code exampleprivate void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e){GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);if (style.CellValueType == typeof(int)){if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null){string columnName = style.TableCellIdentity.Column.Name;GridSummaryColumnDescriptor scd = null;if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count == 0){scd = AddSummaryColumn(columnName);GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor();this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd);}GridSummaryRowDescriptor summaryRow = this.gridGroupingControl1.TableDescriptor.SummaryRows[0];var summarycolDescriptor = summaryRow.SummaryColumns.Cast<GridSummaryColumnDescriptor>().Where(x => x.DataMember == columnName);if (summarycolDescriptor.Count() > 0){var value = summarycolDescriptor.ToList()[0];summaryRow.SummaryColumns.Remove(value);}else{scd = AddSummaryColumn(columnName);summaryRow.SummaryColumns.Add(scd);}//To update the summary.this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors();}}} when we click the second time in the same column - it should disappear only in what we clicked a second time- when we click the third time it adds again
Arulraj 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.
This page will automatically be redirected to the sign-in page in 10 seconds.