Use Linq to get checked CheckBox : CheckBox « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » CheckBoxScreenshots 
Use Linq to get checked CheckBox
Use Linq to get checked CheckBox
   

<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="250" Width="300">
    <StackPanel Name="panel">
        <CheckBox Checked="CheckBox_Checked" Content="First CheckBox" 
                  IsChecked="True" Margin="2" Name="checkbox1" 
                  />
        <Button Content="Get Selected" Margin="5" MaxWidth="100" 
                Click="Button_Click" />
        <TextBlock FontWeight="Bold" Text="Selected CheckBoxes:" />
        <ListBox Margin="5" MinHeight="2cm" Name="listbox" />
    </StackPanel>
</Window>
//File:Window.xaml.vb
Imports System.Linq
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)
      listbox.Items.Clear()
      For Each checkbox As CheckBox In panel.Children.OfType(Of CheckBox)().Where(Function(cbcb.IsChecked = True)
        listbox.Items.Add(checkbox.Name)
      Next
    End Sub
    Private Sub CheckBox_Checked(sender As Object, e As RoutedEventArgs)
      If Not IsInitialized Then
        Return
      End If
      Dim checkbox As CheckBox = TryCast(e.OriginalSource, CheckBox)
      If checkbox IsNot Nothing Then
        MessageBox.Show(checkbox.Name & " is checked.", Title)
      End If
    End Sub


  End Class
End Namespace

   
    
    
  
Related examples in the same category
1.CheckBox checked event listenerCheckBox checked event listener
2.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.
3.Handle CheckBox Unchecked eventsHandle CheckBox Unchecked events
4.Handle CheckBox checked eventsHandle CheckBox checked events
5.Check the CheckBox based on key pressed statesCheck the CheckBox based on key pressed states
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.