• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 798
  • Last Modified:

How can I capture a data field from a specific X, Y coordinate (Hit Test) in a Crystal Report Viewer or Report Document?

I have a .NET project that is using Crystal Decisions CrystalReportViewer and ReportDocument objects to display a Crystal report. I am handling the mouse click event to capture the coordinates and execute some procedures based on what the user has clicked within the report.
Is there anyway to pass the mouse coordinates to the Report Viewer or Report Document do figure out what the user has clicked on?
I have found an object type called CrystalDecisions.Windows.Forms.ReportObjectHitTest, but I have no clue how to use it, and I could not find any documentation that talks about it.
I know its possible to get some info out from the report using the Drill Event, but that only works for groups on properly formatted reports.
0
aferia
Asked:
aferia
  • 10
  • 8
  • 2
  • +1
1 Solution
 
mlmccCommented:
I am not aware of any way to do that.

What version of Crystal and VS?

mlmcc
0
 
aferiaAuthor Commented:
Visual Studio 2008, Crystal 10.
I think that I am close to a solution - I have found this shared function:
CrystalDecisions.Windows.Forms.ReportObjectHitTest.GetObjectFromPoint(position, page)
Now I cant figure out how to get the page object out from the Report Viewer/Document. I'm thinking that this is a "do-nothing" function... they must have implemented the interface without functionality, which is ridonkulous.
0
 
mlmccCommented:
It may also have been something they tried to get to work and couldn't make it work.  They forgot to remove/change the interface.

mlmcc
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Robert SilverSr. Software EngineerCommented:
1. You can create a aspx or Java applet  and
a javascript on mouse button up or down to capture the current position x,y and  store in
a hidden field(s) you can then pass the parameter  into the Crystal Report via a the running of the report
from as submit button action.

Note that the screenX and screenY properties provide the coordinates you may be seeking.
you can test this by creating a javascript mouse button handler and use alerts to debug e.g

var MyEventerObj = {
   addHandler: function(element, type, handler){
       if (element.addEventListener){
            element.addEventListener(type, handler, false);
          }
          else if (element.attachEvent)
          { element.attachEvent("on" + type, handler); }
          else { element["on" + type] = handler; }
          },

          removeHandler: function(element, type, handler)
          {
              if (element.removeEventListener)
            {
               element.removeEventListener(type, handler, false);
            } else if (element.detachEvent)
            { element.detachEvent("on" + type, handler); }
            else { element["on" + type] = null; }
          }
            
};


var div=document.getElementById("idvalueofmine");
MyEventerObj.addHandler(div,"click",    function(event) {
                                                                                         event=MyEventerObj.getEvent(event);
                                                                                         alert("screen coordintes:" +  
                                                                                         event.screenX + "," + event.screenY);
                                                                                     }
                                      ));


Hope that helps
Just store the value instead of alert outputing
0
 
aferiaAuthor Commented:
I'm sorry. I should have mentioned that this is for VB or C# .NET. But it looks like the ASP code would not have behavior that I'm looking for either way. I'm trying to mimic the drill-down behavior that is built-in Crystal reports, but without the need to group and hiding details in the crystal designer.
0
 
Bob LearnedCommented:
Are you looking for something like the Drill event handler?

CrystalReportViewer.Drill Event
http://msdn.microsoft.com/en-us/library/ms227063.aspx
0
 
aferiaAuthor Commented:
Kinda - the drilldown event does not get fired unless the report is configured with groups and such.
I have a simple report that lists Customers - I would like to like to handle an event that lets me know when a user clicks on a Customer #.
When I am using Crystal inside of my application  I can actually see a focus box around the cell when a click on it. I am surprised that there is no way to retrieve it through the API.
0
 
Bob LearnedCommented:
Crystal Reports is fairly convoluted, but with a little Reflector magic, you can see how the hit test is used internally.

1) The CrystalReportViewer has a private PageView field.

2) The PageView is a user control that uses a Document instance.

3) The Document references a PageControl instance.

4) The PageControl class has this method:



protected override void OnClick(EventArgs e)
        {
            Point point = this.getCursorPosInClient();
            if (this.page != null)
            {
                SectionInstance instance;
                ReportObjectInstance objectFromPoint;
                PageView parent = (PageView) base.Parent.Parent.Parent;
                TwipPoint position = new TwipPoint(((int) (this.twipsPerPixel * point.X)) - this.pageLeftMargin, ((int) (this.twipsPerPixel * point.Y)) - this.pageTopMargin);
                ReportObjectHitTest.GetSectionAndObjectFromPoint(position, this.page, out instance, out objectFromPoint);
                if (objectFromPoint != null)
                {
                    if (objectFromPoint is SubreportObjectInstance)
                    {
                        this.DrillDownSubReport(instance, objectFromPoint, position);
                    }
                    else
                    {
                        objectFromPoint = ReportObjectHitTest.GetObjectFromPoint(position, this.page);
                        if ((objectFromPoint.HyperLink != null) && (objectFromPoint.HyperLink.Length > 0))
                        {
                            this.RunHyperlink(objectFromPoint.HyperLink);
                        }
                    }
                }
            }
            base.OnClick(e);
        }

Open in new window

0
 
aferiaAuthor Commented:
Ok. I am trying to get to the PageControl object from the CrystalReportViewer through reflection.
1. I get the "pageView" field. I cant find a "Document" field or property - can you specify where that is coming from?
0
 
aferiaAuthor Commented:
I dont understand how/where to use the code you have included. Where did you get it from?
How were you able to dig that deep?
0
 
aferiaAuthor Commented:
I think I have it working now, but I still cant get to the PageControl instance (I need it to calculate the correct TwipPoint position that I will be passing to the  CrystalDecisions.Windows.Forms.ReportObjectHitTest method.
0
 
Bob LearnedCommented:
If you have Reflector (or something similar like ILSpy), you can load the CrystalDecisions.Windows.Forms assembly, and look at the disassembled code for the library.  The Microsoft.VisualBasic.Compatability library has methods to convert from pixel to twips, and back.
0
 
Bob LearnedCommented:
Attached are the disasssembled versions of the 4 classes:  CrystalReportViewer, DocumentControl, PageControl, and PageView.



CrystalDecisions.Windows.Forms.zip
0
 
aferiaAuthor Commented:
WTF - how did you get this? lol
0
 
Bob LearnedCommented:
ILSpy:

http://wiki.sharpdevelop.net/ILSpy.ashx

Reflector isn't free anymore, but the free version still works for me.
0
 
aferiaAuthor Commented:
Nevermind - just read your first comment - thats amazing! Experts-exhange will have to raise the point cap!
0
 
Bob LearnedCommented:
Add any tool, like Reflector or ILSpy, that can disassemble a .NET assembly, to your "must-have" list...
0
 
aferiaAuthor Commented:
This is deep! Thank you so much!
0
 
Bob LearnedCommented:
It would be interesting to know if you found a solution or not...BTW
0
 
aferiaAuthor Commented:
You can get to the pageControl throught the PageView object as follows:

Dim pageControl As CrystalDecisions.Windows.Forms.PageControl = CType(CType(pageView.Controls(0), Windows.Forms.TabControl).SelectedTab, CrystalDecisions.Windows.Forms.DocumentControl).GetPageControl

Open in new window


Then, all you need to do is use the variables described in the code sniped you posted to calculate crystal's mouse position and pass it to the CrystalDecisions.Windows.Forms.ReportObjectHitTest method.
0
 
Bob LearnedCommented:
Kewl, thank you for sharing!!  *BIG GRIN*
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 8
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now