TDBG: Determine if a column exists

Posted by: edv on 15 August 2018, 9:03 am EST

    • Post Options:
    • Link

    Posted 15 August 2018, 9:03 am EST

    Hi,

    how can I Determine if a column (say the column name is xxx) in tdbg exists?

    Something like that:

    if tdbg1.columns(“xxx”).exist then …

    Thank you in advance.

  • Posted 16 August 2018, 1:38 am EST

    Hi,

    There is no method to directly check for existence of a column.

    If you try to access a column that does not exist then ArgumentException is thrown.

    You can easily add an Extension method called Exists to check if a column exists in the grid.

    Please find the attached sample to see how you can add this extension method.

    Regards.

    CheckColumnExists.zip

  • Posted 17 August 2018, 12:49 am EST

    Hi,

    Here’s an alternative solution that doesn’t require extension method:

    
    Dim isExistAll = _trueDB.Columns.Cast(Of C1DataColumn).Any(Function(x) x.Caption = "1234" OrElse x.DataField = "1234") 
    

    For DisplayColumns in a specific split:

    
    Dim IsExistDisplay = _trueDB.Splits(0).DisplayColumns.Cast(Of C1DisplayColumn).Any(Function(x) x.DataColumn.Caption = "1234" OrElse x.DataColumn.DataField = "1234") 
    

    Regards.

  • Posted 20 August 2018, 6:47 am EST

    Thank you very much.

  • Posted 20 August 2018, 6:50 am EST

    Now I am using

                If tdbg1.DataSource.Columns("xxx") Is Nothing Then Exit Sub
    

    and it works for me!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels