how can i limit the number of selected items in a radTreeListView

3 posts, 0 answers
  1. Biya
    Biya avatar
    4 posts
    Member since:
    Nov 2013

    Posted 04 Nov 2013 Link to this post

    how can i limit the number of selected (checked) items in a radTreeListView. Say after a user has selected (checked) 5 items, a stop them from checking/selecting more items in c#. 

    Which event to i need to handle?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Nov 2013 Link to this post

    Hello Biya,

    You can handle SelectionChanging event and cancel it when required. The number of the selected items can be found through SelectedItems collection of the tree list view. 

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Biya
    Biya avatar
    4 posts
    Member since:
    Nov 2013

    Posted 04 Nov 2013 Link to this post

    this is the XML for the RadTreeListView
     
    <telerik:RadTreeListView x:Name="radTreeListView" ItemsSource="{Binding Items}"
               AutoGenerateColumns="False" Grid.RowSpan="2" SelectionChanged="radTreeListView_SelectionChanged" SelectionMode="Extended" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" SelectionChanging="radTreeListView_SelectionChanging" BeginningEdit="radTreeListView_BeginningEdit">
                   <telerik:RadTreeListView.ChildTableDefinitions>
                       <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
                   </telerik:RadTreeListView.ChildTableDefinitions>
                   <telerik:RadTreeListView.Columns>
                       <telerik:GridViewSelectColumn/>
                       <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"   Header="Name" />
                       </telerik:RadTreeListView.Columns>
               </telerik:RadTreeListView>


    And this is the C# code

    private void radTreeListView_SelectionChanging(object sender, SelectionChangingEventArgs e)
          {
              if (radTreeListView.SelectedItems.Count() > 2)
              {
                  e.Cancel = true;
              }
          }

    BUT it stiill doesn't stop a user from selected more than only 2 items. With that code i can still selected any number of items.
    Why is e.Cancel = true; not working even when the value of radTreeListView.SelectedItems.Count() is greater than 2


Back to Top