1 of 1 people found this helpful
Actually you can update the DisplayUrl Property of the ActiveView Control programmatically. But you will need to refresh the control such that it will load the content from the new display that you have set.
This would take sometime for the display to be loaded in the control and hence you can use the ReadyStateChanged event of the ActiveView control to check that the control is done loading the display, before adding a new trend to it etc. Based on your error, I think you are getting that because you are trying to get the display before the control is done loading it, and hence returning you a null reference.
We can use a simple form application can illustrate this, with ActiveView control (axPbd1) and button (button1) added to the form. And we use the Button_Click event to trigger the change and adding a trend.
Here's a code snippet:
bool Button1_Pressed = false;
private void button1_Click(object sender, EventArgs e)
// a static parameter to let us know that the button to change display and add trend is pressed by user
Button1_Pressed = true;
// change the display url
axPbd1.DisplayURL = @"C:\Users\hanyong\Documents\TestISlimFast.PDI";
// refresh the control to load the new display
private void axPbd1_ReadyStateChange(object sender, AxPBDCtrl._DPbdEvents_ReadyStateChangeEvent e)
// if ActiveView control state is done loading (4) and the change in state caused by the button, then add the trend to display.
if (axPbd1.ReadyState == 4 && Button1_Pressed)
// get display object from ActiveView control
ThisDisplay = (Display)axPbd1.Display;
// add trend to display
MyTrend = (Trend)ThisDisplay.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend);
// add trace to trend
// set trend position
MyTrend.Top = 100;
MyTrend.Left = 100;
// get and set trend format
aFormat = MyTrend.GetFormat();
aFormat.ShowTagName = !aFormat.ShowTagName;
aFormat.ShowServerName = !aFormat.ShowServerName;
MyTrend.TrendTitle = System.DateTime.Now.ToString();
Button1_Pressed = false;
Hope this helps
Thank you many times Han !
That is really working now.
ReadyStateChange was the crucial moment.
Im sure this forum thread will help to somebody else.
No worries, glad that the example is useful for you