This is a migrated thread and some comments may be shown as answers.

Grid Detail Row Expand

1 Answer 231 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gergely
Top achievements
Rank 1
Gergely asked on 11 Sep 2019, 02:39 PM

Dear

I have a rad grid with a detail table, some of the rows have detail row, some of them have none and I want to edit a cell and go throw the whole grid with enter or tab key.
I want to the master row automatically expand when it gets the focus and it has any detailed row. And if its possible i want to make it not from code behind, but with xaml triggers or any other way. 
Is there an easy way to do this?

(My version: 2016.3.1309, please let me know if the solution is implemented in a newer version) 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 13 Sep 2019, 01:24 PM

Hi Gergely,

I believe you can achieve the desired result by creating the following attached behavior and handling the CurrentCellChanged event like so:

    public class ExpandRowBehavior
    {
        public static bool GetIsEnabled(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsEnabledProperty);
        }

        public static void SetIsEnabled(DependencyObject obj, bool value)
        {
            obj.SetValue(IsEnabledProperty, value);
        }

        public static readonly DependencyProperty IsEnabledProperty =
            DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(ExpandRowBehavior), new PropertyMetadata(false, OnIsEnabledChanged));

        private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var grid = d as RadGridView;
            grid.CurrentCellChanged += (s, a) =>
            {
                if (a.NewCell != null)
                {
                    var row = a.NewCell.ParentOfType<GridViewRow>();
                    if (row != null && row.IsExpandable)
                    {
                        row.DetailsVisibility = Visibility.Visible;
                    }
                }
            };
        }
    }

Please note that I've used the IsExpandableBinding property of the control to bind a property of the data items to the IsExpandable property of the GridViewRow element.

For your convenience, I've prepared a small sample project to demonstrate what I have in mind.

Please have a look and let me know if this provides the desired result or if I have misunderstood your requirement in any way.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Gergely
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or