Skip to main content Skip to footer

How To: Control Context Menu for Report Explorer in End User Designer

The End User Designer control is a very popular component which is available with the Professional edition of ActiveReports 7. This control not only allows the end users to view the reports but also provide them the option to make any modifications to the report layout. The Report Explorer present in the End User Designer gives you a visual overview of the report elements in the form of a tree view where each node represents a report element. Using the Report Explorer with any type of report, you can remove controls, add, edit or remove parameters, add a data source, and drag fields onto the report. You can also select the report or any element in the report to display in the Properties Window, where you can modify its properties. It also gives you as developer, the option to provide your end users the ability to modify the reports. However there might be cases when you may not want the end users to make any modifications to the report layout or the datasource of the report. Since the Report Explorer allows all these changes to be controlled, it is required to restrict its functionality. Now having said that, it is important to note that there is no inbuilt mechanism to control the right click behavior on the Report Explorer nodes. When a user right click on any interactive node present in the report explorer, it presents an option to make the required changes. Let us see how it looks like: As I mentioned earlier that there is no default option available to override the default right click behavior, we need to explicitly find a way of doing it. One way, which this blog focuses on, is to identify the point where the right click was made on the screen and quickly shift the focus to a different position so that the corresponding option is not presented to the user. This can be done by importing the "user32.dll" and accessing the mouse_event function there after. The code needs to go just after the Form initialization and would be like:



[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]  
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);  

 private const int MOUSEEVENTF_LEFTDOWN = 0x02;  
 private const int MOUSEEVENTF_LEFTUP = 0x04;  
 private const int MOUSEEVENTF_RIGHTDOWN = 0x08;  
 private const int MOUSEEVENTF_RIGHTUP = 0x10;  

 public void DoMouseClick()  
 {  
    //Call the imported function with the cursor's current position  
    int X = Cursor.Position.X;  
    int Y = Cursor.Position.Y;  
    mouse\_event(MOUSEEVENTF\_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);  
 }

The next thing which we need to do is to access the Report Explorer. Since it is basically a treeview, we access the internal Report Explorer structure and use it with a new treeview object. Following code block performs the functionality:

TreeView rETree = new TreeView();  
private void reportExplorer_Load(object sender, EventArgs e)  
{  
   rETree = (TreeView)reportExplorer.Controls[0].Controls[0];  
   rETree.HideSelection = false;  
   rETree.NodeMouseClick += new TreeNodeMouseClickEventHandler(rETree_NodeMouseClick);  
   rETree.KeyDown += new KeyEventHandler(rETree_KeyDown);  
}  

void rETree_KeyDown(object sender, KeyEventArgs e)  
{  
   if (e.KeyCode == Keys.Delete)  
   {  
     MessageBox.Show("You are not allowed to delete it");  
   }  
}  

void rETree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)  
{  
   if (e.Button == System.Windows.Forms.MouseButtons.Right)  
   {  
     if (e.Node.Level >= 0)  
     {  
        Point p = Cursor.Position;  
        int screenwidth = Screen.PrimaryScreen.Bounds.Width;  
        int leftWidth = screenwidth - p.X;  
        if (leftWidth < 210)  
          p.Y -= 5;  
        else  
          p.X -= 10;  
        Cursor.Position = p;  
        DoMouseClick();  
        if (leftWidth < 210)  
          p.Y += 5;  
        else  
          p.X += 10;  
        Cursor.Position = p;  
        DoMouseClick();  
     }  
  }  
}

So it's all done. Now whenever a user clicks on any interactive node, no option would be available to the user. Download the samples in C# and VB.Net using the links below. ReportExplorer_Click_C# ReportExplorer_Click_VB

MESCIUS inc.

comments powered by Disqus