views:

73

answers:

1

Hi, i am utilising the reportviewer class in my c# application and have a question that isnt essential to fix but something i would like to figure out.

Lets say i launch a new form with a fully docked reportviewer control inside and by the time the form loads the reportviewer has refreshed and is showing my report.

In almost all cases the report will be longer that the vertical size of the form and hence there will be vertical scrollbars.

What i would like to do is figure out a way to give the 'report area' part of the reportviewer control focus or selection so that when the form has loaded - i can immediately use the scroll wheel on my mouse to move up and down the report.

What actually happens is the scroll bars do not work until i click on the report area.

Does any one know how to give that particular area focus?

Here is some of the code i have tried to give that area focus...

int x = this._ReportViewer.Location.X + (this._ReportViewer.Width / 2);
int y = this._ReportViewer.Location.Y + (this._ReportViewer.Height / 2);

this._ReportViewer.RenderingComplete += delegate
{
    this.OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, x, y, 1));
};

Thanks!

+1  A: 

One idea that comes to mind is to loop through the ReportViewer controls recursively. Upon hitting the report area, set focus to that control.

Here is an example snippet:

   //Call this function, by passing it your reportViewer control
   private void RecurseControls(Control ctrl)   
   {
       foreach (Control c in ctrl.Controls) {  //Put breakpoint here to see the controls being looped

           if (c is <TYPEOFCONTROLYOURLOOKINGFOR>) {              
               //CAST c AND SET FOCUS TO IT
           }

           if (c.HasChildren) {  //recurse if children controls exist
               CustomizeRV(c);
           }
       }
   }
Jon