Set DisplayField property for StandaloneTable

562
1
Jump to solution
11-08-2018 07:24 AM
BradJones3
Occasional Contributor

I have a button that loads some standalone tables that are in a 1:M relationship classes with other layers.  I

want to set the DisplayField property of the related tables to the date field so my users can see the date attributes in the popups.

 How do I go about this?  I'm at a loss on where to go from here.

public void SetDisplayField(string tableName, string fieldName)
{
    var mapView = MapView.Active.Map;
    QueuedTask.Run(() =>
    {
        IReadOnlyList<StandaloneTable> tables = mapView.FindStandaloneTables(tableName);
        foreach (var table in tables)
        {
            var cimTableDefinition = table.GetDefinition() as CIMStandaloneTable;
            var displayField = cimTableDefinition.DisplayField;                    
        }
    });
}‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
BradJones3
Occasional Contributor

This what I used in the end.

    public void SetDisplayField(StandaloneTable saTable, string tableName, string fieldName)
        {
            var mapView = MapView.Active.Map;

            QueuedTask.Run(() =>
            {
                //Gets a list of the standalone tables in map with the name specified in the method arguments.
                IReadOnlyList<StandaloneTable> tables = mapView.FindStandaloneTables(tableName);
                foreach (var table in tables)
                {
                    //Gets the list of fields from the stand alone table.
                    var descriptions = table.GetFieldDescriptions(); 
                    foreach (var desc in descriptions)
                    {
                        if (desc.Name == fieldName) // If field name equals "COMPDTTM"
                        {
                            //Creates variable that's equal to "COMPDTTM"
                            string displayName = desc.Name;

                            // Get's the CIM definition from the StandaloneTable
                            var cimTableDefinition = table.GetDefinition() as CIMStandaloneTable;

                            // Set DisplayField property of the cimTableDefinition equall to displayName("COMPDTTM")
                            cimTableDefinition.DisplayField = displayName;
                    
                            // USe the SetDefinition method to apply the modified table definition (cimTableDefninition)
                            saTable.SetDefinition(cimTableDefinition);

                            // Use to check the result when debugin in break point.
                            var result = table.GetDefinition().DisplayField;


                        }
                    }
                }

            });
        }

View solution in original post

0 Kudos
1 Reply
BradJones3
Occasional Contributor

This what I used in the end.

    public void SetDisplayField(StandaloneTable saTable, string tableName, string fieldName)
        {
            var mapView = MapView.Active.Map;

            QueuedTask.Run(() =>
            {
                //Gets a list of the standalone tables in map with the name specified in the method arguments.
                IReadOnlyList<StandaloneTable> tables = mapView.FindStandaloneTables(tableName);
                foreach (var table in tables)
                {
                    //Gets the list of fields from the stand alone table.
                    var descriptions = table.GetFieldDescriptions(); 
                    foreach (var desc in descriptions)
                    {
                        if (desc.Name == fieldName) // If field name equals "COMPDTTM"
                        {
                            //Creates variable that's equal to "COMPDTTM"
                            string displayName = desc.Name;

                            // Get's the CIM definition from the StandaloneTable
                            var cimTableDefinition = table.GetDefinition() as CIMStandaloneTable;

                            // Set DisplayField property of the cimTableDefinition equall to displayName("COMPDTTM")
                            cimTableDefinition.DisplayField = displayName;
                    
                            // USe the SetDefinition method to apply the modified table definition (cimTableDefninition)
                            saTable.SetDefinition(cimTableDefinition);

                            // Use to check the result when debugin in break point.
                            var result = table.GetDefinition().DisplayField;


                        }
                    }
                }

            });
        }
0 Kudos