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

How can I collapse RowDetails?

14 Answers 334 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tolga
Top achievements
Rank 1
Tolga asked on 29 Jun 2010, 08:41 PM
I need to be able to collapse RowDetails after I expanded them. How do I do that. My RowDetaislVisibilityMode = "VisibleWhenSelected". Is there a programmatic approach? If so how?
thakns
--tolga

14 Answers, 1 is accepted

Sort by
0
Paul Dhingra
Top achievements
Rank 1
answered on 30 Jun 2010, 12:40 AM
+1

I too need to find a way to do this - the user can click in the GridViewToggleRowDetailsColumn to make the RowDetails visible or collapsed.

However, I also need to be able to programmatically Collapse an expanded RowDetails area.



Paul.
0
Rossen Hristov
Telerik team
answered on 30 Jun 2010, 08:13 AM
Hi Paul Dhingra,

@Tolga

VisibleWhenSelected means that they are visible when the row is selected and they are collapsed when the row is not selected. You can deselect a row and they will collapse. If you need to do things programmatically then do not set the RowDetailsVisibility mode of the grid but play with each row individually. You can do that via its DetailsVisibility property. Or you can use the special column GridViewToggleRowDetailsColumn. It is up to you.

@Paul

Each GridViewRow has a DetailsVisibility property that does exactly that. As a matter of fact, the toggle button of the GridViewToggleRowDetailsColumn is bound to this exact same property.

@ Both

Please, read the documentation. You will find everything what you need there.

Greetings,
Ross
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
0
Paul Dhingra
Top achievements
Rank 1
answered on 30 Jun 2010, 02:10 PM
Understood, though I should have been more clear - I was already attempting to change the RowDetailsVisibility property, but my problem was that I couldn't determine how to find the GridViewRow in question.  My GridViewToggleRowDetailColumn's ExpandMode="Single", so I was hoping to be able to find the (selected? open?) gridviewrow and set the RowDetailsVisibility during certain event handling.  But all I can seem to locate is the SelectedItem (which is the data item itself, not the GridViewRow).

In any case, I solved this using a different approach, the only time I can seem to find the specific GridViewRow is during the LoadingRowDetails event, so during that event I store a reference to the GridViewRow (e.row), and then use that to change the Visibility when needed.

Paul.
0
Rossen Hristov
Telerik team
answered on 30 Jun 2010, 02:22 PM
Hi Paul Dhingra,

You can find the row from the SelectedItem like this:

var selectedRow = this.radGridView.ItemContainerGenerator.ContainerFromItem(this.radGridView.SelectedItem) as GridViewRow;

if (selectedRow != null)
{
//...
}

I hope this helps.

Kind regards,
Ross
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
0
Paul Dhingra
Top achievements
Rank 1
answered on 30 Jun 2010, 02:25 PM
Yes, that absolutely does help!  I forgot about the ItemContainerGenerator, it's perfect for this (and several other) situations.

Thanks!
0
Tolga
Top achievements
Rank 1
answered on 30 Jun 2010, 04:47 PM
Indeed, that does work, but now I have 2 more questions.

1. How do I loop through all the rows in a GridView
2. How do I trigger a "Row Click" event

thanks

--tolga
0
Yavor Georgiev
Telerik team
answered on 01 Jul 2010, 09:48 AM
Hi Tolga,

 Could you please share a bit more information about what you're trying to accomplish? Looping through UIElements and simulating user input is not a very efficient course of action. Perhaps we'll be able to reach your goals through alternate means.

Sincerely yours,
Yavor Georgiev
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
0
Gerry Connolly
Top achievements
Rank 1
answered on 18 Sep 2010, 07:01 PM
Hi,

I want to make row collapsed when RowDetails is visibile and Rowdetails should collapsed when row is visible.
Is there any method to do it ?

Please reply as soon as possible. I need it urgently.

Thanks
0
Yavor Georgiev
Telerik team
answered on 20 Sep 2010, 12:07 PM
Hello Gerry Connolly,

 You can achieve your goal very easily by modifying the GridViewRow template. Please find attached a sample solution.

Sincerely yours,
Yavor Georgiev
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
0
Gerry Connolly
Top achievements
Rank 1
answered on 02 Oct 2010, 09:01 PM
Hi,
Yavor Georgiev
your solution was good and working for me but now requrement has been changed.

Now I need to open row details on row Click and Row should collpase

I have tried with this in Rowloaded event but I am unable to understand why the code  is not reaching at event row_MouseLeftButtonUP on mouse click
I can not use RowDetailsVisibilityMode="VisibleWhenSelected" because I want to open one rowdetails at a time though I can select mulitiple row
Colud you suggest something the code is below :

 

 

Private Sub GridView_RowLoaded(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.GridView.RowLoadedEventArgs)

 

 

 

 

 

Dim row As GridViewRow = TryCast(e.Row, GridViewRow
If row IsNot Nothing Then  

 

AddHandler row.MouseLeftButtonDown, AddressOf row_MouseLeftButtonUP 

 

 

 

End If  

 

End Sub

 

Private Sub row_MouseLeftButtonUP(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)

 

Dim row As GridViewRow = TryCast(sender, GridViewRow)

 

 

 

 

If row IsNot Nothing Then

 

 

 

 

 

row.DetailsVisibility = System.Windows.Visibility.Visible

 

 

 

 

Dim dp As DetailsPresenter = New DetailsPresenter()

 

 

 

dp.DetailsProvider = row.DetailsProvider 

 

 

Dim dcp As DataCellsPresenter = New DataCellsPresenter()

 

dcp.DataContext = row.DataContext

dcp.Visibility = System.Windows.

 

 

Visibility.Collapsed

 

 

End If

 

 

 

 

 

 

 

 

 

 

End Sub

 

 

 

 

0
Yavor Georgiev
Telerik team
answered on 04 Oct 2010, 01:01 PM
Hello Gerry Connolly,

 Please find attached an update to the sample solution. Unfortunately, your scenario is not achievable when DetailsVisibilityMode=VisibleWhenSelected. I have used the GridViewToggleRowDetails column instead.

Regards,
Yavor Georgiev
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
0
neo e
Top achievements
Rank 1
answered on 12 Jan 2011, 04:02 PM

To bind the rowdetailvisbility to a datamember. I create a custom column to acomplish this.

public class GridViewToggleRowDetailDataColumn : GridViewDataColumn
   {        
       public static readonly DependencyProperty ToggleRowDetailDataMemberProperty =
           DependencyProperty.RegisterAttached("ToggleRowDeatilDataMember", typeof (string),
                                       typeof (GridViewToggleRowDetailDataColumn), new PropertyMetadata(string.Empty));
       public string ToggleRowDetailDataMember
       {
           get { return (string)GetValue(ToggleRowDetailDataMemberProperty); }
           set
           {
               SetValue(ToggleRowDetailDataMemberProperty,value);
           }
       }
       public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
       {
           var currenRow = cell.ParentRow as GridViewRow;
           if (null != currenRow && !string.IsNullOrEmpty(ToggleRowDetailDataMember))
           {
               var binding = new Binding(ToggleRowDetailDataMember)
                            {
                                Source = currenRow.DataContext,
                                Mode = BindingMode.TwoWay,
                                Converter = new BooleanToVisibilityConverter()
                            };
               currenRow.SetBinding(GridViewRow.DetailsVisibilityProperty, binding);
           }
           return base.CreateCellElement(cell, dataItem);            
       }
        
   }
0
Michael Gaigg
Top achievements
Rank 1
answered on 15 Feb 2011, 06:48 AM
Thanks, that did the trick!
0
Tajani
Top achievements
Rank 1
answered on 06 Feb 2014, 12:23 PM
the property ExpandMode="Single" can resolve the problem.

<telerik:GridViewToggleRowDetailsColumn ExpandMode="Single" />

Mohammed
Tags
GridView
Asked by
Tolga
Top achievements
Rank 1
Answers by
Paul Dhingra
Top achievements
Rank 1
Rossen Hristov
Telerik team
Tolga
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Gerry Connolly
Top achievements
Rank 1
neo e
Top achievements
Rank 1
Michael Gaigg
Top achievements
Rank 1
Tajani
Top achievements
Rank 1
Share this question
or