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

QuerCellFormattedText for GridGroupingControl

Thread ID:





22371 Dec 10,2004 02:19 PM UTC Dec 12,2004 09:11 AM UTC WinForms 4
Tags: GridControl
Administrator [Syncfusion]
Asked On December 10, 2004 02:19 PM UTC

Hi, I am using the code below to format the GDBG: this.StrategyDataBoundGrid.Model.QueryCellFormattedText += new Syncfusion.Windows.Forms.Grid.GridCellTextEventHandler(Model_QueryCellFormattedText); private void Model_QueryCellFormattedText(object sender, Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs e) { if(e.Value != null && e.Style.CellIdentity.RowIndex > 0) { if(e.Value is double) { double d = (double) e.Value; e.Text = d.ToString("#,##0.00; (#,##0.00); 0"); e.Handled = true; } else if(e.Value is int) { int i = (int) e.Value; e.Text = i.ToString("#,###; (#,###); 0"); e.Handled = true; } } } I am trying to use the same code for GridGrouping control with slight modification: this.hunterGrid.TableModel.QueryCellFormattedText += new Syncfusion.Windows.Forms.Grid.GridCellTextEventHandler(Model_QueryCellFormattedText); I am able to do what I want to do except I am able to format the SummaryRows. How can I format the text of the summary row? Secondly, I am not able to resize the summary caption column. How can I do that? Thanks, Lalit

Administrator [Syncfusion]
Replied On December 10, 2004 05:37 PM UTC

Hi Lalit, You need to handle the QueryCellStyleInfo event. See following code: private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { switch (e.TableCellIdentity.TableCellType) { case GridTableCellType.SummaryFieldCell: { GridTable table = e.TableCellIdentity.Table; GridSummaryColumnDescriptor sumCol1 = e.TableCellIdentity.SummaryColumn; GridSummaryRow row = e.TableCellIdentity.DisplayElement as GridSummaryRow; //GridSummaryRowDescriptor summaryRowDescriptor = row.SummaryRowDescriptor; if (sumCol1 != null) { string unformattedValue = sumCol1.GetDisplayText(table, row); string formattedText = "*" + unformattedValue; // do formatting here ... e.Style.CellValue = formattedText; e.Handled = true; /* // you could also directly access underlying SummaryDescriptor and get the value directly from there SummaryDescriptor sd1 = sumCol1.SummaryDescriptor; if (sd1 != null) { int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(sd1); ISummary sum1 = el.ParentGroup.GetSummaries(table)[indexOfSd1]; // strong typed - you have to cast to Int32AggregateSummary (or whatever appropriate summary you need in that case ...) DoubleAggregateSummary summary1 = (DoubleAggregateSummary) el.ParentGroup.GetSummaries(table)[indexOfSd1]; e.Style.Text = string.Format("{0:c}", summary1.Average); } */ } break; } } } For resizing individual rows in the grid check out the ResizableRows example that is shipped with the 3.0 Release Candidate. Stefan

Administrator [Syncfusion]
Replied On December 10, 2004 06:55 PM UTC

I am able to do the formatting by: GridSummaryColumnDescriptor colDescriptor; colDescriptor = new GridSummaryColumnDescriptor(columnName); colDescriptor.Format = "{" + this.Summary.Get(columnName) + ":#,###; (#,###); 0}"; Resizable row is not what I want. I would like to have something like SummaryInCaption example (event handler TableModel_QueryCoveredRange). Instead of settiing SummaryCaption width to the width of 2-3 columns, I would like to auto-resize it. Or Auto-resize the first column of the grid to the width of SummaryCation column. Thanks, Lalit

Administrator [Syncfusion]
Replied On December 11, 2004 11:26 PM UTC

Any pointer on this please. Thanks, Lalit

Administrator [Syncfusion]
Replied On December 12, 2004 09:11 AM UTC

For now, you will have to do this yourself using Graphics.MeasureString to get the optimal width for your caption text, and then directly setting the column width. You can use code like this to get the graphics object, and make sure you dispose it after you have finished using it. Here is a example snippet using MeasureString that loops through each column setting the column width based on the max string width. Maybe you can use similar code to size the first column as you want it. private void button2_Click(object sender, System.EventArgs e) { int ticks = Environment.TickCount; this.gridGroupingControl1.BeginUpdate(); Graphics g = Graphics.FromHwnd(this.gridGroupingControl1.TableControl.Handle); for(int j = 1; j


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