Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
iam unable to select the items in a Listbox after scrolling the scrollviewer in WPF.
only able to select the items up to which the listbox is displaying after that when i scroll for the next items, those are unable to select.

sample:
XAML
C#
<ScrollViewer
 x:Name="dataScroller"
 VerticalScrollBarVisibility="Disabled"
 HorizontalScrollBarVisibility="Auto">
    <ListBox
	Name="mylistbox"
	Grid.Row="1"
	HorizontalAlignment="Stretch"
	VerticalAlignment="Bottom"
	Height="50"
	SelectionChanged="Mylistbox_SelectionChanged" />
</ScrollViewer>

<Label
Name="label1"
Content="Label"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="28,13,0,0"
Width="92"
Height="23" />


C# code:

Constructor
C#
public Window1()
   {
      InitializeComponent();
      this.WindowState= WindowState.Maximized;
      List<string> mylist=new List<string> ();
      for(int i=0;i<=50;i++)
      {
        mylist.Add(" item" + i);
      }
            mylistbox.ItemsSource=mylist;
   }
void Mylistbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  label1.Content=mylistbox.SelectedItem.ToString();
}


Plz help how i can select the items in a listbox after scrolling to the next items in the list box

Thanks,
Posted
Updated 23-Jan-12 2:30am
v5
Comments
SteveAdey 23-Jan-12 5:21am    
Why do you need your listbox in a scrollviewer?
KiranBabu M 23-Jan-12 5:33am    
actually i want to include another control in the scroll viewer along with the listbox but i have not updated here.
SteveAdey 23-Jan-12 11:41am    
Unfortunately, I can't see the problem. It seems to select fine.

hi
For ListBox you have to make SelectionMode="Multiple"(This is a ListBox Property) . then it will be Work for you.



Regards
Siraz
 
Share this answer
 
Comments
KiranBabu M 23-Jan-12 6:01am    
it is not working if i make SelectionMode="Multiple"

Why do you use the Height property of the ListBox?


If you want to scroll the whole of the ListBox's content with the outer ScrollViewer, omit the Height property of the wrapped ListBox.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900