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.
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">m_editEvents_OnCreateFeature</SPAN><SPAN class="punctuation token">(</SPAN>ESRI<SPAN class="punctuation token">.</SPAN>ArcGIS<SPAN class="punctuation token">.</SPAN>Geodatabase<SPAN class="punctuation token">.</SPAN>IObject obj<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
IFeature pFeature <SPAN class="operator token">=</SPAN> obj <SPAN class="keyword token">as</SPAN> IFeature<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>pFeature <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">// will never be null on create new feature</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// get the new feature's table name</SPAN>
ITable tbl <SPAN class="operator token">=</SPAN> pFeature<SPAN class="punctuation token">.</SPAN>Table <SPAN class="keyword token">as</SPAN> ITable<SPAN class="punctuation token">;</SPAN>
IDataset dataset <SPAN class="operator token">=</SPAN> tbl <SPAN class="keyword token">as</SPAN> IDataset<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">string</SPAN> sTblName <SPAN class="operator token">=</SPAN> dataset<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Split</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'.'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToLower</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// Implement user OK or Cancel message box</SPAN>
<SPAN class="keyword token">bool</SPAN> resp <SPAN class="operator token">=</SPAN> <SPAN class="token function">GetOKCancelResponse</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Creating New "</SPAN> <SPAN class="operator token">+</SPAN> sTblName<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToUpper</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" Feature"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Do you want to create a new "</SPAN> <SPAN class="operator token">+</SPAN> sTblName <SPAN class="operator token">+</SPAN> <SPAN class="string token">" point?"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>resp <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//Cancel the operation</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// do important stuff</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">bool</SPAN> <SPAN class="token function">GetOKCancelResponse</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">string</SPAN> caption<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">string</SPAN> message<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">bool</SPAN> rslt <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">,</SPAN> caption<SPAN class="punctuation token">,</SPAN>
MessageBoxButtons<SPAN class="punctuation token">.</SPAN>OKCancel<SPAN class="punctuation token">,</SPAN>
MessageBoxIcon<SPAN class="punctuation token">.</SPAN>Question<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// If the no button was pressed ...</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>result <SPAN class="operator token">==</SPAN> DialogResult<SPAN class="punctuation token">.</SPAN>OK<SPAN class="punctuation token">)</SPAN>
rslt <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> rslt<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>