Select to view content in your preferred language

Is it possible to cancel an edit event such as onCreateFeature from an event listener?

760
2
Jump to solution
07-06-2017 04:07 PM
HarlanMarshall
Occasional Contributor

I'm creating an ArcMap extension to listen for onCreateFeature events and set an attribute value on the new feature. I want the user to get an ok/cancel dialog that will either proceed to create the feature or cancel the feature creation based on the user response.

private void m_editEvents_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
{
    IFeature pFeature = obj as IFeature;
    if (pFeature != null) // will never be null on create new feature
    {
        // get the new feature's table name
        ITable tbl = pFeature.Table as ITable;
        IDataset dataset = tbl as IDataset;
        string sTblName = dataset.Name.Split('.')[2].ToLower();

        // Implement user OK or Cancel message box
        bool resp = GetOKCancelResponse("Creating New " + sTblName.ToUpper() + " Feature", "Do you want to create a new " + sTblName + " point?");
        if (resp == false)
        {
            //Cancel the operation
        }
        else
        {
            // do important stuff
        }
    }
}

private bool GetOKCancelResponse(string caption, string message)
{
    bool rslt = false;
    var result = MessageBox.Show(message, caption,
                                    MessageBoxButtons.OKCancel,
                                    MessageBoxIcon.Question);

    // If the no button was pressed ...
    if (result == DialogResult.OK)
        rslt = true;

    return rslt;
}
0 Kudos
1 Solution

Accepted Solutions
JeffMatson
Frequent Contributor

You can use IEditor.AbortOperation().

View solution in original post

2 Replies
JeffMatson
Frequent Contributor

You can use IEditor.AbortOperation().

HarlanMarshall
Occasional Contributor

Thank you Jeff! That worked.

0 Kudos