Set Column Titles Dynamically

SOLVED

Is there a way to dynamically set column titles for a grid on a screen?  I can do this: 

But I want to make it more dynamic, like this, but X3 doesn't like it.

  • +1
    verified answer

    Hi Denise,

    I've never been able to figure it out that way - tried it, but was never successful. However, perhaps you can use a slightly different approach? It may not be as dynamic as you'd/I'd like, but perhaps still provides a bit more flexibility?

    One of the ways to use Titcol is with a straight list of values, rather than specifically saying which row. Here is an explanation from the help file.

    # Let's imagine we have a grid containing CATEG1, CATEG2, CATEG3, CATEG4, CATEG5 in [ITM] mask with CATEG as bottom-page variable
    # Let's define the title of the 3 first columns of a grid by using the title of the Item category
      Titcol [ITM]CATEG mess(1,206,1), mess(1,206,2), mess(1,206,3)

    Just looking at what I see above, you could shorten your code to:

    Titcol [M:YIEX1]NBLIG "", "", "", "", ""

    Of course, you're wanting to also set names dynamically, so let's say you want to leave some column names alone, while replacing others. 

    1. Create an array.    Local char COLNAM(GLONAX3)(10). 
    GLONAX3 represents the length of title columns, and the second value of course being the number of columns you have in your screen.

    2. Loop through the existing screen column names (filter the table AMSKZON by the screen code you're using, and order by NUMLIG) and add the names you want to keep to the corresponding array position, while replacing the others with the custom values you want.

    3. Finally, use the code Titcol [M:YIEX1]NBLIG COLNAM(0), COLNAM(1), COLNAM(2), COLNAM(3), etc.

     

    Again, not fully dynamic, but hopefully provides some of the flexibility you're looking for?

  • 0 in reply to xsMichaelG

    This is exactly what I ended up doing, and it works perfectly!

  • 0 in reply to Denise Hartman

    Kindly use screen field Evaluated title to pass dynamic field name in details section.

  • 0 in reply to VeNu BaBu

    Can you elaborate on how to do this?