update attribute value and refresh tablecontrol

1138
3
10-06-2019 07:38 PM
VictorTey
Esri Contributor

Hi,

ProGuide TableControl · Esri/arcgis-pro-sdk Wiki · GitHub 

I am following this guide. On click of a button, I am attempting to change a attribute value and then save that value in the featureClass and update the tableControl. However, the save seem to be locking the UI thread and the table doesn't updated, the refresh icon just keeps spinning. If I close the pane and open it again, the table is updated.

I have to use featureclass not not featurelayer as the layer I am updating most likely will not be added to the active map. Would anyone be able to advise?

public ICommand AddToMapCommand
        {
            get
            {
                if (_addToMapCommand == null)
                {
                    _addToMapCommand = new RelayCommand(() =>
                    {
                        //var oid = _tableControl.GetObjectIdAsync(_tableControl.ActiveRowIndex).Result;
                       

                        QueuedTask.Run(() =>
                        {
                            IReadOnlyList<long> oids = _tableControl.GetSeletedObjectIds();

                            using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri(@"D:\SDE connection\LEA-304867.sde"))))
                            {
                                using (FeatureClass featClass = geodatabase.OpenDataset<FeatureClass>("arcgis.DBO.polygonfeaturelayer"))
                                {
                                    EditOperation editOperation = new EditOperation();
                                    editOperation.Callback(context => {
                                        QueryFilter queryFilter = new QueryFilter
                                        {
                                            ObjectIDs = oids
                                        };

                                        using (RowCursor cursor = featClass.Search(queryFilter, false))
                                        {
                                            while (cursor.MoveNext())
                                            {
                                                using (Feature f = (Feature)cursor.Current)
                                                {
                                                    f["NAME"] = "Y";
                                                    f.Store();
                                                }
                                            }
                                        }
                                    }, featClass);

                                    bool success = editOperation.Execute();
                                    if (success)
                                    {
                                        Project.Current.SaveEditsAsync();
                                        this._tableControl.Refresh();

                                    }
                                    if (!success) throw new Exception(editOperation.ErrorMessage);

                                }
                            }                            
                        });

                    });
                }
                return _addToMapCommand;
            }
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (2)
0 Kudos
3 Replies
by Anonymous User
Not applicable

Victor,

One thing you'll need to do when updating via a callback is to invalidate the row before and after a store.

Take a look at the Modifying a Row snippet.

VictorTey
Esri Contributor

Sean Jones‌ thanks for that. However that did not work and the UI thread is still hanging. 

Thanks

0 Kudos
by Anonymous User
Not applicable

Hi Victor,

Just use wpf DataGrid and extend it to allow multiselection and then bind with datasource.

That should be easier if you don't have specific purpose to use that TableControl