Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 489773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:50:32+00:00 2026-05-13T01:50:32+00:00

I have a silverlight listbox that is being used as a search result box.

  • 0

I have a silverlight listbox that is being used as a search result box. I’m using dynamic searching (keyups in the search box cause the events to fire to filter this list box’s contents). The issue I’m running into is if the user scrolls down when the box is unfiltered, then does the search, the rebinding of the listbox does not cause the scroll to go back up to the top making the results look like there is only one value in it.

the code I have so far for the listbox is this (This is a simplified version):

XAML:

<Grid x:Name="MainGrid" Rows="2">
    <StackPanel Orientation="Horizontal" Grid.Row="0">
         <TextBlock text="Search" Grid.Row="0" />
         <Textbox x:name="textboxSearch" Keyup="textBoxSearch_KeyUp" width="200" 
                  Height="25"/>
    </StackPanel>
    <ListBox x:Name="SearchResultBox" Visibility="Visible" Grid.Row="1"
             ScrollViewer.HorizontalScrollBarVisibility="Auto"
             ScrollViewer.VerticalscrollbarVisibility="Auto">
         <ListBox.ItemTemplate>
              <DataTemplate>
                   <StackPanel Orientation="Vertical">
                        <TextBlock Text="{Binding ReportName}" />
                        <TextBlock Text="{Binding ReportDescription}" />
                   </StackPanel>
              </DataTemplate>
         </Listbox.ItemTemplate>
    </ListBox>
</Grid>

VB:

Imports System.Threading
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Partial Public Class ucSearch
     Inherits UserControl
     Private WithEvents BGwork As New BackgroundWorker()
     Private mReportList as New List(Of cFilter)

     Public Sub New()
          InitializeComponent()
          FillReportList()
          NewFilterList()
     End Sub

     Private Sub FillReportList()
          mReportList.Add(new cFilter("Report A", "Report A desc")
          mReportList.Add(new cFilter("Report B", "Report B desc")
          mReportList.Add(new cFilter("Report C", "Report C desc")
          mReportList.Add(new cFilter("Report D", "Report D desc")
          mReportList.Add(new cFilter("Report E", "Report E desc")
          mReportList.Add(new cFilter("Report F", "Report F desc")
          mReportList.Add(new cFilter("Report G", "Report G desc")
          mReportList.Add(new cFilter("Report H", "Report H desc")
          mReportList.Add(new cFilter("Report I", "Report I desc")
          mReportList.Add(new cFilter("Report J", "Report J desc")
          mReportList.Add(new cFilter("Report K", "Report K desc")
          mReportList.Add(new cFilter("Report L", "Report L desc")
          mReportList.Add(new cFilter("Report M", "Report M desc")
     End Sub

     Private Sub textboxSearch_KeyUp(ByVal sender as System.Object, _
                                     ByVal e as System.Windows.Input.KeyeventArgs)
         NewFilterList()
     End Sub

     Private Sub NewFilterList()
          If BGwork.IsBusy Then
               If Not BGWork.cancellationPending Then BGwork.CancelAsync()
               Exit Sub
          End If

          With BGwork
               .WorkerSupportsCancellation = True
               .RunWorkerAsync(textboxSearch.Text)
          End With
     End Sub

     Private Sub BGwork_DoWork(ByVal sender as Object, _
                               ByVal e as System.ComponentModel.DoWorkEventArgs) _
                               Handles BGwork.DoWork
          Dim Filtered as New List(of cFilter)
          If textboxSearch.Text.Length > 0
               dim q = FROM ri In mReportList Where ri.Reportname.ToLower.contains(textboxSearch.Text.ToLower) Select ri
               Filtered = q
          Else
               Filtered = mReportList
          End If
          Dim RTN as List(Of cFilter) = Filtered
          e.Cancel = False
          e.Result = RTN
     End Sub

     Private Sub BGwork_RunWorkerCompleted(ByVal sender As Object_
                                           ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _
                                           Handles BGwork.RunWorkerCompleted
          If e.Cancelled Then
               NewFilterList()
               Exit Sub
          End If

          Dim RTN as cFilter = TryCast(e.Result, cFilter)
          If IsNothing(RTN) Then Exit Sub

          SearchResultBox.ItemsSource = RTN
          SearchResultBox.InvalidateArrange()
     End Sub
 End Class

 Public Class cFilter
      Inherits BaseDataClass
      Private mReportName as String = ""
      Private mReportDescription as String = ""

      Public Sub New()
           mReportName = ""
           mReportDescription = ""
      End Sub

      Public Sub New(ByVal reportName as String, ByVal reportDescription as String)
           mReportName = reportName
           mReportDescription = reportDescription
      End Sub

      Public Property ReportName() as String
           Get
                Return mReportName
           End Get
           Set(ByVal value as String)
                mReportName = value
           End Set
      End Property

      Public Property ReportDescription() as String
           Get
                Return mReportDescription
           End Get
           Set(ByVal value as String)
                mReportDescription = value
           End Set
      End Property
 End Class

Again this is simplified greatly from what is going on (I go to database to get report names, etc). When I rebind the listbox, how do I get it to scroll all the way to have the first item at the top of the list? Since I don’t have access to the scrollviewer control from within the ListBox object, do I have to make a scrollviewer control that surrounds the listbox and then set where it’s view is from there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:50:32+00:00Added an answer on May 13, 2026 at 1:50 am

    After looking at this post

    Automatic Scrolling in a Silverlight List Box

    I tried the following and it worked fine for me.

     theListBox.ItemsSource = data;
     theListBox.UpdateLayout();
     theListBox.ScrollIntoView(theListBox.Items[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox in Silverlight that has a list of items inside. Each
I have a silverlight ListBox that has it's ItemsSource set. From the C# code
In Silverlight, I have a Vertical ListBox that has a Horizontal ListBox for each
I have a Silverlight application that has a ListBox of a specific width. I
I have a ListBox in a Silverlight Application. I'm trying to make an editable
I have a Silverlight project that uses MVVM with Prism. I followed http://www.telerik.com/help/silverlight/patterns-and-practices-eventtocommand-prism.html I
I have a Silverlight ModelViewViewModel project that I would like to expose a property
I have a Silverlight 2.0 site that works in dev. I have Copy Local
I have a ListBox that uses a WrapPanel for its ItemsPanel , a custom
in my Silverlight 4 Application I have an ObservableCollection that I data bind to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.