Symptom
- The list in the Group Tree can become very long (100+ elements)
- When the user selects an element from the Group Tree, the scroll position on the Group Tree is lost
- How to obtain the current scroll position of the Group Tree and re-assign it after the report is reloaded?
Resolution
- Hide the Crystal Report viewer GroupTree (KB 1183704 - How to display or hide the Group Tree in CrystalReportViewer control through code in Crystal Reports 2008)
- Create a custom "Group Tree" using a ListBox and position it next to the CrystalReportViewer as in the following markup:
<asp:ListBox ID="lstStockCode" runat="server" Width="185px" Height="760px" Font-Size="10pt" AutoPostBack="true"
OnSelectedIndexChanged="lstStockCode_SelectedIndexChanged" DataTextField="StockCode" DataValueField="ID" BackColor="#E4E4EC"
style="position: relative; top: 30px; border-width: 0px;" Visible="false"></asp:ListBox>
- Add a ListBox and bind it to the same data source as the report is bound to
- Use the following code to search the displayed report for the value selected in the ListBox:
Protected Sub myElement_SelectedIndexChanged(sender As Object, e As EventArgs)
If ViewState("PrevListIndex") Is Nothing Then
CrystalReportViewer1.SearchAndHighlightText(myElement.SelectedItem.Text, CrystalDecisions.[Shared].SearchDirection.Forward)
ElseIf Convert.ToInt32(ViewState("PrevListIndex")) < myElement.SelectedIndex Then
CrystalReportViewer1.SearchAndHighlightText(myElement.SelectedItem.Text, CrystalDecisions.[Shared].SearchDirection.Forward)
ElseIf Convert.ToInt32(ViewState("PrevListIndex")) > myElement.SelectedIndex Then
CrystalReportViewer1.SearchAndHighlightText(myElement.SelectedItem.Text, CrystalDecisions.[Shared].SearchDirection.Backward)
End If
ViewState("PrevListIndex") = myElement.SelectedIndex
CrystalReportViewer1.ToolbarStyle.Width = Unit.Parse("1096px")
myElement.Focus()
End Sub
Keywords
grouptree post back scrol control viewer , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To
Product
Crystal Reports 2008 V1