TreeView, ContainerBindingCollection and IsSelectionActive

6 posts, 0 answers
  1. Espen
    Espen avatar
    16 posts
    Member since:
    Sep 2011

    Posted 13 Oct 2010 Link to this post

    I've currently made use of the IsExpanded property in the ContainerBindingCollection with mode TwoWay, and this works fine. When I add IsSelectionActive this also works, but only if the initial value on object I've bound to is false. If I try to set the initial value to true, everything crashes...and there's no real exception where I can see what actually goes wrong. Intended or not? IsSelectionActive has a public setter, so should work just as fine is IsExpanded shouldn't it?

    Edit: I'm using the latest Q2 of the RadControls for Silverlight.
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 14 Oct 2010 Link to this post

    Hello Espen,

    In fact, RadTreeViewItem's IsSelectionActive property has a public getter and internal setter.



    Greetings,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Espen
    Espen avatar
    16 posts
    Member since:
    Sep 2011

    Posted 14 Oct 2010 Link to this post

    You need to fix your documentation then :)

    "Gets or sets whether the tree item selection is active - e.g. the item is selected and the treeview is focused.  

     C#  
    public bool IsSelectionActive {get; set;}
    "

    That being said...the real underlying issue here is that when I open a view with a treeview (via composite framework and such), I have trouble giving the first RadTreeViewItem focus. It is selected through the IsSelected property, but it has no focus. item.Focus() doesn't seem to help either. I actually have to click inside the treeview to make the treeviewitem getting focus. I'm not sure if this is related to the RadTreeView at all actually. Maybe you know that though, or how I can get the item to get focus.
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 19 Oct 2010 Link to this post

    Hi Espen,

    The documentation will be updated as soon as possible. I've logged this issue in our public issue tracking system under the name "Remove "set" from IsSelectionActive documentation" and it will be available for tracking tomorrow the latest. I've also updated your Telerik points accordingly.

    As for the other issue...it is strange that item.Focus() does not work. For example, I created an application with the code bellow and it worked as expected.

    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel>
            <ScrollViewer>
                <telerik:RadTreeView>
                    <!--Simpsons Family-->
                    <telerik:RadTreeViewItem Header="Simpsons" IsExpanded="True">
                        <telerik:RadTreeViewItem x:Name="homer" Header="Homer" />
                        <telerik:RadTreeViewItem Header="Marge" />
                        <telerik:RadTreeViewItem Header="Bart" />
                        <telerik:RadTreeViewItem Header="Lisa" />
                        <telerik:RadTreeViewItem Header="Maggie" />
                    </telerik:RadTreeViewItem>
                    <!--Flanders Family-->
                    <telerik:RadTreeViewItem Header="Flanders" IsExpanded="True">
                        <telerik:RadTreeViewItem Header="Ned" />
                        <telerik:RadTreeViewItem Header="Maude" />
                        <telerik:RadTreeViewItem Header="Todd" />
                        <telerik:RadTreeViewItem Header="Rod" />
                    </telerik:RadTreeViewItem>
                </telerik:RadTreeView>
            </ScrollViewer>
            <Button Content="Focus Homer" Click="Button_Click" />
        </StackPanel>
    </Grid>

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        this.homer.Focus();
    }

    Try investigating who is stealing the focus from the TreeViewItem and make it unfocusable. Let me know if I can be of further assistance.

    Regards,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Espen
    Espen avatar
    16 posts
    Member since:
    Sep 2011

    Posted 19 Oct 2010 Link to this post

    I should probably have been clearer, but adding a button like you have done works fine. Problem is that I want it to have focus when the view opens, so I run it in the Loaded event (or actually after the treeviewitems has been loaded from a WCF data service)...and that's not working. I find it weird if the error is with the treeview though...it's just that I'm not doing any .Focus() anywhere else...and as such this should just work :P I will investigate further though.
  7. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 19 Oct 2010 Link to this post

    Hi Espen,

    This might be shot in the dark, but let me suggest one more thing. When the TreeView gets its data from the service (assuming in the Completed event handler), call the focus in a Dispatcher. Something like:

    // pseudo code implementation
    private void WorkCompleted (sender, args) <-- this is the event handler for the completed event of the web service
    {
       // populate the treeview with data
       treeView.ItemsSource = args.Result;
     
       // focus the first item in the treeview
       this.Dispatcher.BeginInvoke(() =>
       {
          (treeView.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem).Focus();
       });
    }


    All the best,
    Kiril Stanoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner