Menu1 | |----Submenu1 | |----Command1 | |----Command2 |----Submenu2 | |----Command1 | |----Command2 |----Submenu3
internal static void PopulateDataSubMenu(ICommandBar pMenu, string entitySetName)
{
try
{
OleDbConnection dataConnection = new OleDbConnection();
dataConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=\\\\ad.sfwmd.gov\\dfsroot\\data\\err_gis\\applications\\dev\\mdb\\rimGISLibDatabase\\mdb\\GISLIBFeaterClassName1.mdb";
dataConnection.Open();
OleDbCommand dataCommand = new OleDbCommand();
dataCommand.Connection = dataConnection;
dataCommand.CommandText = "SELECT distinct(Order1ClassName) " +
"FROM qryorder1 " +
"WHERE Order1SetName = '" + entitySetName + "'";
OleDbDataReader dataReader = dataCommand.ExecuteReader();
object idx = 0;
int counter = 0;
while (dataReader.Read())
{
string className = dataReader.GetString(0);
idx = counter;
CmdTest2 cmdTest3 = new CmdTest2(entitySetName + " - " + className, entitySetName, className);
UID uid = new UIDClass();
uid.Value = cmdTest3; <---CRASH HERE
pMenu.Add(uid, ref idx);
counter++;
}
dataReader.Close();
dataConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}hi,
you must pass the command name or UID value to UID.value.
example:
uid.Value = "esriEditor.SaveEditsCommand";
or
uid.Value = "{B479F48A-199D-11D1-9646-0000F8037368}";
** you must replace B479F48A-199D-11D1-9646-0000F8037368 by your GUID command value
Vincent
string className = dataReader.GetString(0); idx = counter; CmdTest2 cmdTest3 = new CmdTest2(entitySetName + " - " + className, entitySetName, className); UID uid = new UID(); uid.Value = "RegGSS.cmdTest3"; pMenu.Add(uid, ref idx); counter++;
string className = dataReader.GetString(0);
idx = counter;
CmdTest2 cmdTest3 = new CmdTest2(entitySetName + " - " + className, entitySetName, className);
UID uid = new UID();
uid.Value = "{adc85ec2-c1c8-48ce-a975-1de2f0b393ff}";
pMenu.Add(uid, ref idx);
counter++; ICommandBar pSetEditMenu = pDataEditorMenu.CreateMenu("SetEditLayer", ref idx);
ICommandItem pSetEditItem = pSetEditMenu as ICommandItem;
pSetEditItem.Caption = "Set Edit Layer";
idx = 0;
pSetEditMenu.Add(MakeUID("RegGSS.Commands.CmdSetEditLayerScratchLine"), ref idx);
idx = 1;
pSetEditMenu.Add(MakeUID("RegGSS.Commands.CmdSetEditLayerScratchPoly"), ref idx);
internal static UID MakeUID(string id)
{
try
{
UID uid = new UIDClass();
uid.Value = id;
return uid;
}
catch (Exception ex)
{
ClsLogErrors.LogError(ex.StackTrace, ex.Message, "MakeUID", null);
MessageBox.Show("An error has occured." + "\r\n" + "The GIS group has been notified of this problem.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}