This is a migrated thread and some comments may be shown as answers.
Substring function in RadGridView column expression
4 Answers 34 Views
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 12 Feb 2020, 05:58 PM

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

Sort by
0
Nadya
Telerik team
answered on 17 Feb 2020, 07:49 AM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
James
Top achievements
Rank 1
answered on 17 Feb 2020, 10:38 PM

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

0
Nadya
Telerik team
answered on 19 Feb 2020, 10:50 AM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
James
Top achievements
Rank 1
answered on 19 Feb 2020, 07:53 PM

Hi Nadya - thanks for your latest reply - super useful!

Best wishes

James

Asked by
James
Top achievements
Rank 1
Answers by
Nadya
Telerik team
James
Top achievements
Rank 1
Share this question
or