Click here to Skip to main content
11,718,016 members (82,467 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF checkbox ListView Keyboard , +
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">
           <listview.itemtemplate>
               <datatemplate>
                   <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}"
                       </Label>-->
                   <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">
                           <checkbox.content>
                               <binding path="DisplayText" />
                           </checkbox.content>
                       </bc:checkboxextended>
                   </stackpanel>
               </datatemplate>
           </listview.itemtemplate>
       </listview>



CheckboxExtended Codebehind

Public Class CheckBoxExtended
       Inherits CheckBox
    Public Property IsCheckedReal() As System.Nullable(Of Boolean)
           Get
               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
Edited 8-Mar-13 1:00am
v5

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

  Print Answers RSS
0 OriginalGriff 215
1 F-ES Sitecore 210
2 Maciej Los 140
3 Jochen Arndt 120
4 Andy Lanng 115
0 Sergey Alexandrovich Kryukov 1,649
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2015
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