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

How do I display a calculated value on a bound column

Thread ID:

Created:

Updated:

Platform:

Replies:

46227 Jul 9,2006 02:15 PM Jul 12,2006 05:59 AM Windows Forms 3
loading
Tags: GridControl
Bill Langlais
Asked On July 9, 2006 02:15 PM

Hi, I have a read-only column which is bound to a field in a DataTable. I want to claculate the displayed value based on the underlying data in the field. Can I do this without having to create another column and hiding the underlying data?

Administrator [Syncfusion]
Replied On July 10, 2006 01:06 PM

One way you can do this is to handle the grid.DrawCellDisplayText and there set e.DisplayText to be what you want. void gridDataBoundGrid1_DrawCellDisplayText(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellDisplayTextEventArgs e) { if (e.ColIndex == gridDataBoundGrid1.Binder.NameToColIndex("Col2")) { e.DisplayText = "someComputedTextFrom " + e.Style.Text; } }

Bill Langlais
Replied On July 11, 2006 10:12 PM

Hi, I am using a GridGroupingControl and have been unable to find: gridDataBoundGrid1.Binder.NameToColIndex("Col2") I have tried the following code: System::Void Form1::srgDrawCellDisplayText(System::Object * sender, Syncfusion::Windows::Forms::Grid::Grouping::GridTableControlDrawCellDisplayTextEventArgs * e) { if(e->Inner->ColIndex == e->TableControl->Model->NameToColIndex(S"Run Distance")) { String *Label = String::Format(S"Indexes {0} {1}", __box(e->Inner->RowIndex), __box(e->Inner->ColIndex)); Debug(Label, S"{0} {1}", e->Inner->Style->CellValue, e->Inner->Style->CellType); // bool IsRecord = Element::IsRecord(e->Inner); if(e->Inner->Style->CellType == S"TextBox") { Double x = Convert::ToDouble(e->Inner->Style->CellValue) / 5280; String *Value = x.ToString(DistFmt); e->Inner->DisplayText = Value; Label = String::Format(S"Value {0} {1}", __box(e->Inner->RowIndex), __box(e->Inner->ColIndex)); Debug(Label, S"{0} {1} {2} {3}", e->Inner->Style->CellValue, e->Inner->Style->CellType, Value, e->Inner->Style->ValueMember); } } I find that the Column Index returned by e->TableControl->Model->NameToColIndex(S"Run Distance") does not always come back with the correct index depending on what level I am in in the nested grid. The column name S"Run Distance" exists in several of the nested tables. Am I using the wrong code to figure out what the right column is for the data column I am trying to modify the display value? Thanks!

Administrator [Syncfusion]
Replied On July 12, 2006 05:59 AM

In the grouping grid, you can cast e.Inner.Style to a GridTableCellStyleInfo object and get the information you need from it. Here is C# code that makes Col1 display 2 times what is in Col2. (Col2 is a column of doubles.) private void gridGroupingControl1_TableControlDrawCellDisplayText(object sender, GridTableControlDrawCellDisplayTextEventArgs e) { //make Col1 be 2 times the value in Col2 GridTableCellStyleInfo style = (GridTableCellStyleInfo)e.Inner.Style; if(style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.MappingName == "Col1") { GridRecord rec = style.TableCellIdentity.DisplayElement.GetRecord() as GridRecord; if(rec != null) { double d = (double) rec.GetValue("Col2"); e.Inner.DisplayText = string.Format("{0}", 2 * d); } } }

CONFIRMATION

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.

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.

;