selecting a single row in hierachical grid

6 posts, 0 answers
  1. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 23 Feb 2010 Link to this post

    is there a way to force the grid to only select a single row even in child tables

    what seems to be happening (2010 Q1) is that i can select a row in the parent table and also select a row in the child even though i have selectionmode set to single

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 23 Feb 2010 Link to this post

    Hi CAMERON MOLYNEUX,

    At the moment every grid (no matter if parent or child) has its own selection which is independent from any other grid. We will take into consideration your feedback and we will consider covering such scenarios in a future version.

    Currently you could try the following workaround which will keep only one item selected

    GridViewDataControl lastSelectionControl;
      
    public Window1()
    {
        InitializeComponent();
      
        this.clubsGrid.ItemsSource = Club.GetClubs();
        this.clubsGrid.SelectionChanged += new System.EventHandler<SelectionChangeEventArgs>(clubsGrid_SelectionChanged);
      
    }
      
    private bool changingSelection;
      
    void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
    {
        if (changingSelection)
            return;
      
        // get the control on which the actual selection was performed
        var currentSelectionControl = e.OriginalSource as GridViewDataControl;
      
        this.changingSelection = true;
      
        if (currentSelectionControl != this.lastSelectionControl && 
            this.lastSelectionControl != null && 
            e.AddedItems.Count > 0)
        {
            this.lastSelectionControl.SelectedItems.Clear();
              
        }
      
        this.lastSelectionControl = currentSelectionControl;
        this.changingSelection = false;
    }

    Hope this helps.

    Best wishes,
    Milan
    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. UI for WPF is Visual Studio 2017 Ready
  4. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 24 Feb 2010 Link to this post

    that worked a treat.  thank you.

    quick further question, is there a way to identify the id of the parent of a child table (when i say parent i mean upper most parent)

    Thanks
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Feb 2010 Link to this post

    Hi Cameron Molyneux,

    Could you please clarify a bit - I am not sure if I have understood the question correctly. Are you referring to the data property that represents the parent-child relation? When would you like to retrieve this information? 


    Best wishes,
    Milan
    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. Cameron Molyneux
    Cameron Molyneux avatar
    79 posts
    Member since:
    Jan 2010

    Posted 24 Feb 2010 Link to this post

    What i mean is that i want to return the top parent row for whatever child i click on, regardless of how many levels of hierachy its down.

    i.e if i select a row in a single nested table i want to find the parent row, but if i click a row in a table that is three levels down i want the parent.parent.parentrow ..

    sorry if i'm not being clear
  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 01 Mar 2010 Link to this post

    Hi Cameron Molyneux,

    Thank you for the clarification. you can achieve that with the following code:

    // required namespaces: Telerik.Windows.Controls; System.Linq;
      
    void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
    {
        // control that initiated the selection (can be on any level) 
        var selectionDataControl = (GridViewDataControl)e.OriginalSource;
      
        // et the top-most row
        var masterRow = this.GetParentsOfType<GridViewRow>(selectionDataControl).LastOrDefault();
    }
      
    private IEnumerable<T> GetParentsOfType<T>(FrameworkElement element) where T : FrameworkElement
    {
        FrameworkElement currentElement = element;
        T parent = null;
        List<T> parents = new List<T>();
      
        while ((parent = currentElement.ParentOfType<T>()) != null)
        {
            parents.Add(parent);
            currentElement = parent;
        }
      
        return parents;
    }


    Greetings,
    Milan
    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
UI for WPF is Visual Studio 2017 Ready