14 Answers, 1 is accepted
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.
@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
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.
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
Thanks!
1. How do I loop through all the rows in a GridView
2. How do I trigger a "Row Click" event
thanks
--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
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
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
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
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
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);
}
}
<telerik:GridViewToggleRowDetailsColumn ExpandMode="Single" />
Mohammed