TDBG: Determine if a column exists

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

  • Posted 15 August 2018, 12:03 am EST


    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.
  • Replied 15 August 2018, 4:38 pm EST


    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.

  • Replied 16 August 2018, 3:49 pm EST


    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")

  • Replied 19 August 2018, 9:47 pm EST

    Thank you very much.
  • Marked as Answer

    Replied 19 August 2018, 9:50 pm 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