I have a Crystal Report created in Visual Studio 2008 which displays various stock codes with their prices. The Group Tree for the Crystal Report Viewer is enabled & displays a list of the stock codes for easy navigation. The list in the Group Tree can become quite long (100+ stock codes), which causes a scroll bar to appear.
Problem is, when the user selects a stock code from the Group Tree, the page posts back & the scroll position on the Group Tree is lost. This is particularly frustrating, especially when you’re working with stock codes that are towards the end of the list.
Is there any way that I could get the current scroll position of the Group Tree, save it & re-assign it after the report has reloaded?
Some things I have tried, but without much success:
The Group Tree is rendered as a div, but without an ID. So I’ve retrieved the Group Tree control from the server side by using the Report Viewers Controls collection (it’s the 4th control in the collection) & checked its UniqueID value. I then used that to call document.getElementById(), but this always returns null.
Also, I’m unable to use the control I retrieve from server-side, as I can’t find the class (CrystalDecisions.Web.CrystalReportGroupTree), which is the type supplied when calling GetType() on the Group Tree control.
Any assistance in this matter will be greatly appreciated.
So I’ve found a solution that works pretty well. I’ve created my own “Group Tree” using a
ListBox& positioned it next to theCrystalReportViewer, hiding the viewers actualGroupTree. TheListBoxmaintains its own scroll position, as well as the current selection. The added bonus with this approach is that users can use the arrow keys to navigate theGroupTree, as long as it has focus.My method of implementation is as follows:
I’ve added a standard
ListBoxcontrol to the page & positioned it to the left of theCrystalReportViewer. The markup is as follows:The
CrystalReportVieweris initially hidden, until the report criteria have been selected, at which point both the Viewer &ListBoxwill become visible.Next, bind the
ListBoxto a data source that returns the same data as what the report is bound to. In my case, I had created a method to retrieve stock codes using the same SQL query as the Stored Procedure my report is bound to.Lastly, search the displayed Report for the value selected in the
ListBox. Below is a sample of the SelectedIndexChanged Event:Because the search direction needs to specified for the
CrystalReportViewer, I just store my current search index & determine whether I’m searching further down or back up in the report, seeing as myListBoxis returned using the same query as my report & thus is in the same order as the report data.A few things of interest about this implementation, mostly in terms of styling. The supplied code does not make provision for the repositioning of the
CrystalReportViewer Toolbar. While theListBoxsits in line with the report, it only has whitespace above it where theToolbarwould normally sit. Also, the TreeView-like dotted lines do not appear inside theListBox. I haven’t played around with using aTreeViewcontrol as opposed to aListBoxto achieve the same effect but I believe it to be very doable.Even with these differences in terms of look & feel, the client was unaware that a new control was built to achieve this goal.