Substring function in RadGridView column expression

5 posts, 0 answers
  1. James
    James avatar
    9 posts
    Member since:
    Jul 2015

    Posted 12 Feb Link to this post

    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

  2. Nadya
    Admin
    Nadya avatar
    301 posts

    Posted 17 Feb Link to this post

    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.
  3. James
    James avatar
    9 posts
    Member since:
    Jul 2015

    Posted 17 Feb in reply to Nadya Link to this post

    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

  4. Nadya
    Admin
    Nadya avatar
    301 posts

    Posted 19 Feb Link to this post

    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.
  5. James
    James avatar
    9 posts
    Member since:
    Jul 2015

    Posted 19 Feb in reply to Nadya Link to this post

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

    Best wishes

    James

Back to Top