Hi there,
I've been tasked with migrating DataTable functionality to Telerik RadGridView in a C# WinForms app.
DataTable code sample:
var taxColumn = new DataColumn();
taxColumn.DataType = System.Type.GetType("System.String");
taxColumn.ColumnName = "tax";
taxColumn.Expression = "SUBSTRING('ABC',2,3)";
My attempt to do the equivalent using a RadGridView TextBoxColumn fails with "unknown function SUBSTRING()".
Is there any similar functionality in RadGridView to the Substring function in DataColumn please? It's essential to be able to write expressions that do substirng operations in the app I'm working on.
Thanks as ever for your help!
Kind regards, James
4 Answers, 1 is accepted
Hello James,
RadGridView offers a calculated column. A calculated column is identified by an expression. The only condition necessary to make a regular column behave like a calculated column is to set an expression to it. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/columns/calculated-columns-(column-expressions)
You can use the substring expression as shown in the below example:
GridViewTextBoxColumn col = new GridViewTextBoxColumn();
col.Name = "Calculated Column";
col.HeaderText = "Substring Column";
radGridView1.Columns.Add(col);
radGridView1.Columns["Calculated Column"].Expression = "SUBSTR(ContactTitle, 0,5)";
I hope this helps. Let me know if I can assist you further.
Regards,
Nadya
Progress Telerik
Hi Nadya,
thanks so much for your reply - that's incredibly useful, I've got my example working now!
A question - in the article you linked to, I couldn't find the SUBSTR keyword mentioned anywhere, and the Microsoft equievalent is SUBSTRING - is there a page that lists all Telerik keywords please?
Best wishes, James
Hello James,
I am glad that this works for you.
You can find the expressions here. Note, that this article contains all Telerik keyword expressions. Since we try to consistently approve our documentation, we will consider adding a separate section in our documentation that lists the column expressions for the calculated columns in RadGridView.
I hope this information helps. Do not hesitate to contact us if you have other questions.
Regards,
Nadya
Progress Telerik
Hi Nadya - thanks for your latest reply - super useful!
Best wishes
James
What would cause it not to recognize the field?
Expression = SUBSTR(Risk,2,99)
Field name = "Risk"
The field Risk does exist in the table, but I still get