SAP Knowledge Base Article - Public

1626523 - Scroll position on the Crystal Reports .NET viewer Group Tree is lost on PostBack

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

<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