Ok - I am a little confused. I have a line of code that I have put in a Try.Catch - and it is giving me the following message:
Object reference not set to an instance of an object.
The line of code is :
MainFormRef.xtraTabControl_Results.TabPages.Add(xtraTabPage_Results);
These are DevExpress controls.
Here I am adding the TabPage that I create at the beginning of the routine - to the TabControl_Results that is a control I have placed on the form. So - I know that both objects exist. I have even added code to reference them - and it does not throw an exception.
As well - this is a routine that I call from another place in the code - and it works fine. So - there must be something I am doing that is causing this error in the current code path. But I have to admit I am puzzled.
Is there a way to tell which object reference is Null? It does not seem to be either of the objects in the line of code that is causing the exception??
Any suggestions would be appreciated!
Code - that is causing the exception
public DevExpress.XtraTab.XtraTabPage AddResultGridTabObject()
{
DevExpress.XtraTab.XtraTabPage xtraTabPage_Results = new DevExpress.XtraTab.XtraTabPage();
var NewTabObject = new UserControl_ResultsTab();
NewTabObject.TrackerId = SavedTrackerId;
NewTabObject.FormType = TAIIDFormType.ftResultsGrid;
TabList.Add(NewTabObject);
xtraTabPage_Results.Controls.Add(NewTabObject); // Add to the Collection
NewTabObject.Dock = DockStyle.Fill; // Now have it take up the entire Tab
try
{
MessageBox.Show("Name: " +
MainFormRef.xtraTabControl_Results.TabPages.Count.ToString());
MainFormRef.xtraTabControl_Results.TabPages.Add(xtraTabPage_Results);
}
catch (Exception Error)
{
MessageBox.Show("Error while Saved Encrypted File: " + Error.Message);
}
MainFormRef.xtraTabControl_Results.SelectedTabPage = xtraTabPage_Results;
return xtraTabPage_Results;
}