I have a C# Add-In with two combo boxes. The first box contains the Map layer names and the second contains the field names of the layer chosen in the first box.
Each combo box has it's own class which I have created using the Add-In wizard in VS 2010.
The problem I am having is when the user selects a layer from the layer combo box it triggers the layer combo onSelChange routine but there is no way to access the field combo box's loadFields routine. If the loadFields routine is made static then all the this.Value and this.Add etc cannot be accessed.
If an instance of the field combo box is created then it all runs fine but the fields box on the screen is empty.
If a static instance of the field and layers combo boxes is used it all runs fine but again, the fields box is empty.
My code for the startup button is:
// Layer combo public static comboLayer m_pLayers; // Fields combo public static comboField m_pFields;
protected override void OnClick() | |
{ | |
// Startup | |
string sError = ""; |
try | |
{ | |
m_pLayers = new comboLayer(); | |
sError = m_pLayers.loadLayers(); | |
if (sError.Length > 0) | |
{ | |
sError = "clsFilter.OnClick" + "\r\n" + sError; | |
MessageBox.Show(sError); | |
return; | |
} |
m_pFields = new comboField(); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true); | |
System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1); | |
int iLineNo = pFrame.GetFileLineNumber(); | |
MessageBox.Show("Error: clsFilter.OnClick; Line: " + iLineNo + " \r\n" + ex.Message); | |
} |
} |
That looks awful! Why have all the blank lines been added to the code? What happened to the indentation?
My code for the layer OnSelChange:
protected override void OnSelChange(int cookie) | |
{ | |
string sError; | |
string sLayer; | |
// Reset the fields in the Fields combo | |
try | |
{ | |
sError = ""; | |
if (cookie == -1) return; |
sLayer = Value; | |
clsFilter.m_sCurrentLayer = sLayer; | |
// Load the fields | |
sError = clsFilter.m_pFields.loadFields(sLayer); | |
if (sError.Length > 0) | |
{ | |
sError = "OnSelChange;" + "\r\n" + sError; | |
MessageBox.Show(sError); | |
} |
base.OnSelChange(cookie); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true); | |
System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1); | |
int iLineNo = pFrame.GetFileLineNumber(); | |
sError = "Error: OnSelChange; Line: " + iLineNo + " \r\n" + ex.Message; | |
} |
} |
I have a suspicion that I'm not doing any of this correctly (otherwise I would have found an answer in the forum).
I'm probably not putting the code in correctly either but I can't find a Help document for writing forum entries.
Thanks,
John