Get selected item count from Listbox : ListBox Selection « Windows Presentation Foundation « VB.Net Tutorial






<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="AboutDialog" ListBox.SelectionChanged="ListBox_SelectionChanged"
        Button.Click="Button_Click"
        Title="About WPF Unleashed" SizeToContent="WidthAndHeight"
        Background="OrangeRed">
  <StackPanel>
    <Label FontWeight="Bold" FontSize="20" Foreground="White">
      WPF
    </Label>
    <Label>License</Label>
    <Label>Installed Dll:</Label>
    <ListBox>
      <ListBoxItem>1</ListBoxItem>
      <ListBoxItem>2</ListBoxItem>
      <ListBoxItem>3</ListBoxItem>
      <ListBoxItem>4</ListBoxItem>
      <ListBoxItem>5</ListBoxItem>
      <ListBoxItem>6</ListBoxItem>
      <ListBoxItem>7</ListBoxItem>
      <ListBoxItem>8</ListBoxItem>
      <ListBoxItem>9</ListBoxItem>
    </ListBox>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
      <Button MinWidth="75" Margin="10">Help</Button>
      <Button MinWidth="75" Margin="10">OK</Button>
    </StackPanel>
    <StatusBar>test</StatusBar>
  </StackPanel>
</Window>
//File:Window.xaml.vb
Imports System.Windows
Imports System.Windows.Controls

Public Partial Class AboutDialog
  Inherits Window
  Public Sub New()
    InitializeComponent()
  End Sub

  Private Sub ListBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
    If e.AddedItems.Count > 0 Then
      MessageBox.Show("You just selected " & Convert.ToString(e.AddedItems(0)))
    End If
  End Sub

  Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    MessageBox.Show("You just clicked " & Convert.ToString(e.Source))
  End Sub
End Class
WPF Get Selected Item Count From Listox








16.30.ListBox Selection
16.30.1.Set selected index for ListBoxSet selected index for ListBox
16.30.2.ListBox Selected Index, Item, ValueListBox Selected Index, Item, Value
16.30.3.ListBox and SelectionModeListBox and SelectionMode
16.30.4.Get selected item from ListBoxGet selected item from ListBox
16.30.5.Get selected item count from ListboxGet selected item count from Listbox
16.30.6.View and Select Items Using a ListView and Select Items Using a List
16.30.7.Set text to TextBlock for selected list itemSet text to TextBlock for selected list item
16.30.8.Select All and unselect allSelect All and unselect all
16.30.9.Get Selected Item from ListBox 2Get Selected Item from ListBox 2
16.30.10.Select All ListBox ItemsSelect All ListBox Items
16.30.11.This list box allows multiple user selections.This list box allows multiple user selections.
16.30.12.ListBox SelectionMode=SingleListBox SelectionMode=Single
16.30.13.ListBox selection changed eventListBox selection changed event