cancel
Showing results for 
Search instead for 
Did you mean: 

Using InitialFocus Property to Get Rid of Dotted Margin Border

ido_millet
Active Contributor
0 Kudos

In my testing, none of the possible values for the InitialFocus property of the .NET Crystal Viewer Control can get rid of the initial dotted gray border indicating the page margins (see image below). The user has to manually click inside the page to select another object or click outside on a different control to get rid of that border.

That property was added (thanks to Don Williams) in response to a similar question years ago.
Has anyone managed to get rid of that border on initial preview? If so, how?

Accepted Solutions (1)

Accepted Solutions (1)

DonWilliams
Active Contributor
0 Kudos

Hi Ido,

Soda suggested this:

Just added below code in InitializeComponent

this.crystalReportViewer1.InitialFocus = CrystalDecisions.Windows.Forms.UIComponent.ToolBar;

Then it will not set the focus on the report page content, but on the toolbar.

I tried it and it does work.

Also I changed the check if Count - 0 to and AND and not an OR

// if no groups in report hide the group tree in viewer
if (rptClientDoc.DataDefController.DataDefinition.Groups.Count == 0 && rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count == 0)
{
    crystalReportViewer1.InitialFocus = CrystalDecisions.Windows.Forms.UIComponent.ToolBar;
    //crystalReportViewer1.SetFocusOn(UIComponent.Page);
    //crystalReportViewer1.ToolPanelView = ToolPanelViewType.ParameterPanel;
    //crystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
}
else
{
    /// this sets the focus on the group set to none and then sets it to the group again to get rid of the dotted line around the main viewer area.
    crystalReportViewer1.ToolPanelView = ToolPanelViewType.ParameterPanel;
    crystalReportViewer1.SetFocusOn(UIComponent.ParameterPanel);
    //crystalReportViewer1.ToolPanelView = ToolPanelViewType.GroupTree;
    //crystalReportViewer1.SetFocusOn(UIComponent.GroupTree);
    //crystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
    //crystalReportViewer1.SetFocusOn(UIComponent.ParameterPanel);
}

Have a great day

Don

Answers (5)

Answers (5)

ido_millet
Active Contributor
0 Kudos

Thanks, Don.
Since it works for you, I'll mark it as solved.

Perhaps it's a question of method call timing the calls but for me even that variation doesn't work.
Also, it makes no sense that a control property exposed through the designer for the control has to be called in code in unexpected places. It should work either by simply setting the property in the designer or by setting it once in the parent form load event.

DonWilliams
Active Contributor
0 Kudos

Hi IDo,

But now you have my curiosity triggered...

I see the difference, I'm using SetFocusOn and you are using InitialFocus.

I'll check with R&D and see if there is anything we could use.

Have a great day

Don

ido_millet
Active Contributor
0 Kudos

Thanks, Don, but that still doesn't work in my testing.

Again, let's drop this. It's not worth chasing.

DonWilliams
Active Contributor
0 Kudos

Hi Ido,

You are correct, using my code doesn't work if you don't have a Group or Parameter in the report.

So the trick is to turn it on and then off and then it works, not really a direct fix but more of a way to get around it.

// if no groups in report hide the group tree in viewer
if (rptClientDoc.DataDefController.DataDefinition.Groups.Count == 0 || rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count == 0)
{
    crystalReportViewer1.SetFocusOn(UIComponent.Page);
    crystalReportViewer1.ToolPanelView = ToolPanelViewType.ParameterPanel;
    crystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
}

Note you do see the Group/Parameter tree show up and then go away so you could handle it differently if that's not "nice" enough for you or try using the GroupPanel and see if that works better.

Have fun

Don

DonWilliams
Active Contributor
0 Kudos

Hi Ido,

Try this to set the focus on another part of the page:


// if no groups in report hide the group tree in viewer
if (rptClientDoc.DataDefController.DataDefinition.Groups.Count == 0)
{
    crystalReportViewer1.SetFocusOn(UIComponent.Page);
    crystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
}
else
{
    // this sets the focus on the group set to none and then sets it to the group again to get rid of the dotted line around the main viewer area.
    crystalReportViewer1.ToolPanelView = ToolPanelViewType.ParameterPanel;
    crystalReportViewer1.SetFocusOn(UIComponent.ParameterPanel);
    //crystalReportViewer1.ToolPanelView = ToolPanelViewType.GroupTree;
    //crystalReportViewer1.SetFocusOn(UIComponent.GroupTree);
}

Have fun

Don

ido_millet
Active Contributor
0 Kudos

Thanks, Don! Just tested with your code but the dotted border remains.

Please don't spend more time on this; it's not worth chasing.
Strange that a property added to address exactly this issue doesn't do the trick.