Handles ComboBox SelectionChanged events. : ComboBox « Windows Presentation Foundation « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows Presentation Foundation » ComboBox 
16.12.6.Handles ComboBox SelectionChanged events.
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="100" Width="300">
    <StackPanel>
        <ComboBox Name="comboBox" IsEditable="True" Margin="5" SelectionChanged="ComboBox_SelectionChanged">
            <ComboBoxItem Content="ComboBox Item 1" Selected="ComboBoxItem_Selected" />
            <ComboBoxItem Content="ComboBox Item 2" Selected="ComboBoxItem_Selected" />
            <ComboBoxItem Content="ComboBox Item 3" Selected="ComboBoxItem_Selected" IsSelected="True"/>
            <ComboBoxItem Content="ComboBox Item 4" Selected="ComboBoxItem_Selected" />
            <ComboBoxItem Content="ComboBox Item 5" Selected="ComboBoxItem_Selected" />
        </ComboBox>
        <Button Content="Get Selected" Margin="5" Width="100" Click="Button_Click" />
    </StackPanel>
</Window>

//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls

Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Public Sub New()
      InitializeComponent()
    End Sub
    Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
      Dim item As ComboBoxItem = TryCast(comboBox.SelectedItem, ComboBoxItem)

      If item IsNot Nothing Then
        MessageBox.Show("Current item: " & Convert.ToString(item.Content), Title)
      ElseIf Not [String].IsNullOrEmpty(comboBox.TextThen
        MessageBox.Show("Text entered: " + comboBox.Text, Title)
      End If
    End Sub

    Private Sub ComboBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)

      If Not IsInitialized Then
        Return
      End If

      Dim item As ComboBoxItem = TryCast(comboBox.SelectedItem, ComboBoxItem)

      If item IsNot Nothing Then
        MessageBox.Show("Selected item: " & Convert.ToString(item.Content), Title)
      End If
    End Sub

    Private Sub ComboBoxItem_Selected(sender As Object, e As RoutedEventArgs)
      If Not IsInitialized Then
        Return
      End If

      Dim item As ComboBoxItem = TryCast(e.OriginalSource, ComboBoxItem)

      If item IsNot Nothing Then
        MessageBox.Show(Convert.ToString(item.Content" was selected.", Title)
      End If
    End Sub
  End Class
End Namespace
WPF Handles Combo Box Selection Changed Events
16.12.ComboBox
16.12.1.ComboBox TestComboBox Test
16.12.2.Bind ComboBox to ListBox ItemsSourceBind ComboBox to ListBox ItemsSource
16.12.3.ComboBox with ComboBoxItemComboBox with ComboBoxItem
16.12.4.Gets the currently selected ComboBoxItem when the user clicks the Button.Gets the currently selected ComboBoxItem when the user clicks the Button.
16.12.5.if the user has entered text into the ComboBox instead.if the user has entered text into the ComboBox instead.
16.12.6.Handles ComboBox SelectionChanged events.Handles ComboBox SelectionChanged events.
16.12.7.Handles ComboBoxItem Selected events.Handles ComboBoxItem Selected events.
16.12.8.View and Select Items Using a ComboBoxView and Select Items Using a ComboBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.