This is a migrated thread and some comments may be shown as answers.

Calculated Column Value Issue

1 Answer 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Guy
Top achievements
Rank 1
Guy asked on 06 Oct 2011, 02:25 PM
Hi All,

I'm having a strange problem which I can't seem to work out the reason for. I have a series of columns of which one is calculated. When I go to save the values (be it a new row or an update), the field which the calculated column is linked with does not get updated.

My code for creating the calculated column is as follows:

GridViewDecimalColumn col = new GridViewDecimalColumn();
            col.Name = "Total";
            col.HeaderText = "Total";
            col.FormatString = "{0:c0}";
            col.MaxWidth = 90;
            col.MinWidth = 90;
            col.Width = 90;
            col.FieldName = "Total";
            col.FormatInfo = CultureInfo.CreateSpecificCulture("en-GB");
            radGridView1.Columns.Add(col);
            radGridView1.Columns["Total"].Expression = "IsNull(Ink, 0) + IsNull(PB_Products, 0) + IsNull(Office_Supplies, 0) + IsNull(Freight, 0)";
            radGridView1.Columns.Move(11, 9);

For the Save Button, I'm using TableAdapter.Update()

Where abouts have I gone wrong?

Regards,

Guy

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 10 Oct 2011, 01:23 PM
Hello Guy,

Thank you for your question.

A calculated RadGridView column cannot be bound to a data source (even by defining its FieldName property). This column receives the values of its cells from the calculations of its Expression. You should implement your own logic to read the values from the calculated column and write them in the data source.

I hope it helps. Please write back if you have additional questions.

Best regards,
Alexander
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
GridView
Asked by
Guy
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or