Click here to Skip to main content
13,090,678 members (44,650 online)
Rate this:
Please Sign up or sign in to vote.
I have listview with Checkbox Items that are not HardCoded in XAML i load them during run time,
I have two scenarios
***- Listview items Hardcoded

- ListView items loaded Through Itemsource***

ListviewItems with Checkbox HardCoded

> Apple , Apple1 , Ball, Bottom, Mango, Fruit, Ear, Items, etc..
In this scenario, If i Press A first item that starts with letter **A** will get Focus and again Pressing A Focus set to next Item that starts with letter **A**, if it reaches the last item starts with letter **A** then again if i press A it has to goto the first item that has starting letter **A**.
This works perfect when i do hardcode the **ListViewItem**
But Unable to Select the CheckBox Through Keyboard.

ListviewItems with Checkbox Loaded Dynamically

If i load them through **ItemsSource** within **DataTemplate** i cannot acheive the above feature andalso unable to select Checkbox using Keyboard.

Listview items to be loaded

<listview name="LV" itemssource="{Binding Responses}" borderthickness="2" tag="{Binding GUID}" removed="Khaki" margin="5">
                   <stackpanel x:name="Sp1" orientation="Vertical" height="Auto" datacontext="{Binding Path=.}" xmlns:x="#unknown">
                       <!--<Label x:Name="lbl"  BorderBrush="Black" BorderThickness="2" Margin=" 0,5,0,5"
                             Height="{Binding ActualHeight}"  Background="#336699" HorizontalAlignment="Stretch"   Content="{Binding Path = ShowHeader}"  Visibility="{Binding Path= ShowHeader,
                              Converter={StaticResource Header}}" Padding="0" FontStretch="UltraCondensed"  FontWeight="Bold" Foreground="WhiteSmoke"  FontSize="18" FontFamily="Sego">

                   IsCheckedReal="{Binding Path=Checked, Mode=TwoWay}"
                   <bc:checkboxextended checked="McCheckBox_Checked" margin="5" unchecked="McCheckBox_Unchecked" ischeckedreal="{Binding Path=Checked, RelativeSource={RelativeSource FindAncestor,  AncestorType={x:Type ListViewItem}}}" fontfamily="Verdana" fontsize="12" xmlns:bc="#unknown">
                               <binding path="DisplayText" />

CheckboxExtended Codebehind

Public Class CheckBoxExtended
       Inherits CheckBox
    Public Property IsCheckedReal() As System.Nullable(Of Boolean)
               Return CType(GetValue(IsCheckedRealProperty), System.Nullable(Of Boolean))
           End Get
           Set(ByVal value As System.Nullable(Of Boolean))
               SetValue(IsCheckedRealProperty, value)
           End Set
       End Property

            Public Shared ReadOnly IsCheckedRealProperty As DependencyProperty = DependencyProperty.Register("IsCheckedReal", GetType(System.Nullable(Of Boolean)), GetType(CheckBoxExtended), New FrameworkPropertyMetadata(False, FrameworkPropertyMetadataOptions.Journal Or FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, AddressOf IsCheckedRealChanged))

       Public Shared Sub IsCheckedRealChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
           m_bIsChanging = True
           DirectCast(d, CheckBoxExtended).IsChecked = CBool(e.NewValue)
           m_bIsChanging = False
       End Sub
  ' Using a DependencyProperty as the backing store for IsCheckedReal. This enables animation, styling, binding, etc...
   End Class

1. I need to travel the items by pressing the starting letter thrugh Keyboard(This is default feature of Listview,Its not working when i do it within datatemplate)
2. Need to check and Uncheck the checkboxItems
Posted 8-Mar-13 0:49am
Updated 8-Mar-13 1:00am

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100