<Window x:Class="winCustomPKChooser" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="CheckListBox Demo" Height="300" Width="300" > <ListBox x:Name="lstCheckListBox" Height="185" /> </Window>
Private Sub AddItemsToListBox() Dim chkCheckBoxToAdd as CheckBox For nLoop as Integer = 1 to 10 chkCheckBoxToAdd = New CheckBox() chkCheckBoxToAdd.IsChecked = False chkCheckBoxToAdd.Content = "Item " & nLoop.ToString() AddHandler chkCheckBoxToAdd.Checked _ , AddressOf lstColumnName_ItemCheck AddHandler chkCheckBoxToAdd.Unchecked _ , AddressOf lstColumnName_ItemUncheck lstColumnName.Items.Add(chkCheckBoxToAdd) Next End Sub Private Sub lstColumnName_ItemCheck(ByVal sender As Object _ , ByVal e As System.Windows.RoutedEventArgs _ ) 'Do something when an item gets checked. 'If you need for something the checkbox 'which was checked use the CType(e.OriginalSource, CheckBox). End Sub Private Sub lstColumnName_ItemUncheck(ByVal sender As Object _ , ByVal e As System.Windows.RoutedEventArgs _ ) 'Do something when an item gets unchecked. 'If you need for something the checkbox 'which was unchecked use the CType(e.OriginalSource, CheckBox). End Sub
Labels: .NET Framework, CheckListBox, WPF, XAML