I have following methods in my application:
private void Menu_Click(object sender, RadRoutedEventArgs e)
{
RadMenuItem m1 = (RadMenuItem)sender;
if (m1.Header.ToString() == "Collapse All")
{
foreach (CrossReferralItem item in referralGrid.Items)
{
var row = (GridViewRow)this.referralGrid.ItemContainerGenerator.ContainerFromItem(item);
if (row != null)
{
row.DetailsVisibility = Visibility.Collapsed;
}
}
referralGrid.SelectedItem = null;
}
else
{
foreach (CrossReferralItem item in referralGrid.Items)
{
var row = (GridViewRow)this.referralGrid.ItemContainerGenerator.ContainerFromItem(item);
if (row != null)
{
row.DetailsVisibility = Visibility.Visible;
}
}
}
}
private void OnClick(object sender, MouseButtonEventArgs e)
{
var selectedRow = (GridViewRow)this.referralGrid.ItemContainerGenerator.ContainerFromItem(this.referralGrid.SelectedItem);
if (selectedRow != null)
{
if (selectedRow.DetailsVisibility == Visibility.Visible)
{
selectedRow.DetailsVisibility = Visibility.Collapsed;
}
else
{
selectedRow.DetailsVisibility = Visibility.Visible;
}
}
}
The issue is that if user clicks on one row ,then row details is visible which is fine but after that 'Collapse All' menu item will not work. It will not collapse the row visibility of the previuos selected row. This works sometimes and sometimes not. It happens because
ItemContainerGenerator.ContainerFromItem
is returned as null for few rows. How to solve this issue?
13 Answers, 1 is accepted
Generally this will return null if the item is outside of the view area.
Regards,Vlad
the Telerik team
EnableRowVirtualization
="False" EnableColumnVirtualization="False"
for my grid in *.xaml file
I have similar problem - I want to expand/collapse rows selected via GridViewSelectColumn, in response to a button click.
Turning off virtualization is not an option because of performance reasons.
Probably there is some way to do this even if ItemContainerGenerator.ContainerFromItem returns null because the collapsed state is always correctly restored when scrolling so I assume that the collapsed state is not lost even if ItemContainerGenerator.ContainerFromItem is null because then the expanded rows would be collapsed when they leave current view. The question is if this property is exposed and can be modified ?
regards
Pawel
Just a quick question: Are you dealing with hierarchical rows or with row details?
Sincerely yours,
Milan
the Telerik team
I'm dealing with row details
regards
Pawel
Row details have a special mode which allows them to expand automatically when their parent row is selected. Setting RowDetailsVisibilitymode to VisisbleWhenSelected which enable this functionality and you will be able to expand details with the help of our GridViewSelectColumn.
Best wishes,Milan
the Telerik team
regards
Pawel
This functionality is not supported by the grid out of the box but I have prepared a sample solution which demonstrated a possible implementation.
Kind regards,
Milan
the Telerik team
Thank you
regards
Pawel
I want to open a RowDetail of a GridView depending from one of its Item's value.
I've tried a foreach on every items but the GridViewRow returned with the helps of GridView.ItemContainerGenerator.ContainerFromItem(Item) is always null. The Item isn't null.
I've tried your solution but it didn't work for me.
visibleRow.Item is always null.
foreach (var visibleRow in this.myGridView.ChildrenOfType<GridViewRow>())
{
// this.itemsToExpand.Count>0!
if (this.itemsToExpand.Contains(visibleRow.Item)) // <-- visibleRow.Item is always null.
{
itemsToExpand.Remove(visibleRow.Item);
visibleRow.DetailsVisibility = Visibility.Visible;
visibleRow.Background = new SolidColorBrush(Colors.Orange);
}
}How can I open a single RowDetail by code from outside the grid.
Thanks,
Fred
Hi Frédéric,
Is the detail that you are trying to open visible? If it is not you will not be able to find its row since RadGRidView would only generated UI element for the visible element only. One way to resolve this is to turn the vertical virtualization off by setting EnableRowVirtualization = false. Be ware that this might result in higher memory usage and slower start times.
Kind regards,
Milan
the Telerik team
I've managed to do what I expected this way:
In the Constructor I subscribed t this event:
mygrid.RowLoaded += new EventHandler<RowLoadedEventArgs>(mygrid_RowLoaded);Then in the following method I get the row and its Item.
Then I check if its value equals zero and color its background in red and open the detail view.
void mygrid_RowLoaded(object sender, RowLoadedEventArgs e) { var row = e.Row as GridViewRow; if (row != null) { if (row.Item != null) { myObject o = (myObject)row.Item; if (o != null && o.Value == 0) { row.Background = new SolidColorBrush(Colors.Red); row.DetailsVisibility = Visibility.Visible; } } } }Thanks for your help!
Fred
