Hi,
I am facing a problem with the current selection item in the attributes pane's tree view. The use case is let us suppose we already have some features or standalone tables selected in the attribute pane. And in my case I have a custom dock pane from where I am adding new row or rows in my standalone table. So, in this case I am selecting that row at the end of my edit operation which will lead to that item to get added in the attribute pane. But the problem is that newly added item of my standalone table is not getting selected in the attribute pane. On contrary its getting resetted. How resetted? If before my operation if I have selected multiple features of same type and manually selected third item from that type. After my operation selected item will not be there but to the first item of that type(even when you are moving from attribute pane to somewhere else it is resetting again).
But in my case I wanted the selected item to change to my newly added item. And how to keep the selected item there only till any other operation(meaning any other new item is added)?
For selection I used below line:
standaloneTable.Select(new QueryFilter { ObjectIDs = new List<long> { newId } }, SelectionCombinationMethod.Add);
I have used all the SelectionCombinationMethods also but still the result is same.
@Wolf @UmaHarano @GKmieliauskas @MichaelHirschheimer @NarelleChedzey
Hi,
At first I suggest you to use selection of EditOperation itself. EditOperation has property SelectNewFeatures. Set it to true and your new feature/row will be selected automatically.
And comment your selection.
@GKmieliauskas I updated this property to true with my selection line as commented. And now my table row is not even visible in attribute pane.
And fyi the edit operation I am using is on standalone table and not the feature. Not sure any difference that will make.
Do you see your new row in standalone table? If yes, is this row selected?
Using 'SelectNewFeatures = true' doesn't retain any previous selections, so you have to set the EditOperation.SelectNewFeatures to false. Instead, you can use the RowToken returned by the Create method to get the newly created object id. Later you can use the RowToken.ObjectId.Value to add the newly created record to the existing selection. The snipped below works for FeatureClasses:
try
{
await QueuedTask.Run(() =>
{
// get the currently selected features in the map
var selectedFeatures = MapView.Active.Map.GetSelection();
// get the first layer and its corresponding selected feature OIDs
var firstSelectionSet = selectedFeatures.ToDictionary().First();
// create an instance of the inspector class
var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
// load the first selected feature into the inspector using the first OID from the list of object IDs
var mapMember = firstSelectionSet.Key;
var oid = firstSelectionSet.Value[0];
inspector.Load(mapMember, oid);
//Create new feature from an existing inspector (copying the feature)
var createOp = new EditOperation
{
Name = "Copy first selected feature",
SelectNewFeatures = false
};
var rowToken = createOp.Create(inspector.MapMember, inspector); // inspector.ToDictionary(a => a.FieldName, a => a.CurrentValue)
if (createOp.IsEmpty)
{
MessageBox.Show($@"Record oid: {oid} in layer: [{mapMember.Name}] was not duplicated");
}
else
{
var result = createOp.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
if (!result)
MessageBox.Show($@"Copying record oid: {oid} in layer: [{mapMember.Name}] failed: [{createOp.ErrorMessage}]");
else
{
var newOid = rowToken.ObjectID.Value;
MessageBox.Show($@"New record oid: {newOid} in layer: [{mapMember.Name}]");
// now add this record to the existing selection
(mapMember as BasicFeatureLayer).Select(new QueryFilter() { ObjectIDs = new long[] { newOid } }, SelectionCombinationMethod.Add);
}
}
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I will try the standalone table and see if that makes a difference.
This works fine with StandaloneTables as well:
Code snippet:
try
{
QueuedTask.Run(() =>
{
// get the currently selected features in the map
var selectedFeatures = MapView.Active.Map.GetSelection();
// get the first table and its corresponding selected feature OIDs
var firstSelectionSet = selectedFeatures.ToDictionary().First(sel => sel.Key is StandaloneTable);
// create an instance of the inspector class
var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
// load the first selected feature into the inspector using the first OID from the list of object IDs
var mapMember = firstSelectionSet.Key;
var oid = firstSelectionSet.Value[0];
inspector.Load(mapMember, oid);
//Create new feature from an existing inspector (copying the feature)
var createOp = new EditOperation
{
Name = "Copy first selected row",
SelectNewFeatures = false
};
var rowToken = createOp.Create(inspector.MapMember, inspector); // inspector.ToDictionary(a => a.FieldName, a => a.CurrentValue)
if (createOp.IsEmpty)
{
MessageBox.Show($@"Record oid: {oid} in table: [{mapMember.Name}] was not duplicated");
}
else
{
var result = createOp.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
if (!result)
MessageBox.Show($@"Copying record oid: {oid} in table: [{mapMember.Name}] failed: [{createOp.ErrorMessage}]");
else
{
var newOid = rowToken.ObjectID.Value;
MessageBox.Show($@"New record oid: {newOid} in table: [{mapMember.Name}]");
// now add this record to the existing selection
(mapMember as StandaloneTable).Select(new QueryFilter() { ObjectIDs = new long[] { newOid } }, SelectionCombinationMethod.Add);
}
}
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
@Wolf I am facing an issue where the editing operation is failing. And also curious will this work in my case where there is already some other feature is selected in the attribute pane and when editing and selecting mine selection will shift from the previous feature to my new feature?
If your edit operation is failing, you have to debug the cause. Usually if you create new records the cause is invalid attribute column names, or the attribute column value is either bad or has an incompatible data type. Examine the error message of the edit operation to get some idea on what went wrong.
As for your selection question:
I am not clear what use case you are asking for. For example:
Let's say there are two rows in your target FeatureClass (or StandAloneTable) selected like in the example below (OID 1 and 3 are selected):
Now comes your edit operation and creates one new row. From here there are multiple options, which one do you try to implement?
1) the new row (OID 5) is added to the existing selection:
2) the new row (OID 5) becomes the only selected row in the selection:
1. Yes I have checked these 2 causes but thats not the case and its just throwing a very generic error which is Edit operation failed.
2. My use case is something like this first I have selected a feature named Feature1 in the current map and in this feature whatever oids are selected same will appear in the attribute pane with the current selection on the first oid.
Now next I will select my standalone table which is StandaloneT1 with one or multiple oids in this table. How it is different from first selection is from where this selection is happening. First selection is just a basic selection from the active map but the second selection is from custom UI. Now what should happen in this case for me that both Feature1 and StandaloneT1 should appear in the attribute pane with current selection shifting from Feature1 to StandaloneT1. But this is not happening when I am doing just a select on my table. What is happening that the StandaloneT1 oids are also appearing in the attribute pane but the selection is still appearing on the Feature1.
And if next I will select the same standalone table again with different oids previous oids should disappear and new oids should appear with selection still on my standalone table.
Feature1 oids are still there because we haven't cleared out the selection from the map. So any selection from the map should work as it is but when after map selection my table oids are selected from the custom UI current selection should appear on them.
regarding the "throwing a very generic error which is Edit operation failed", can you please share the EditOperation code snippet and the screenshot of your database fields?