
Zbigniew Kozłowski
Top achievements
Rank 1
Zbigniew Kozłowski
asked on 01 Oct 2010, 10:45 AM
Hi,
i got a problem with getting selected row when grid is groupped. I got event on
GridView.RowDetailsProvider.PropertyChanged
than in void:
var selectedRow = (GridViewRow)this.ListGridView.ItemContainerGenerator.ContainerFromItem(this.ListGridView.SelectedItem);
but it works only when grid is not groupped. How can i get GridViewRow from group?
i got a problem with getting selected row when grid is groupped. I got event on
GridView.RowDetailsProvider.PropertyChanged
than in void:
var selectedRow = (GridViewRow)this.ListGridView.ItemContainerGenerator.ContainerFromItem(this.ListGridView.SelectedItem);
but it works only when grid is not groupped. How can i get GridViewRow from group?
7 Answers, 1 is accepted
0
Hello Zbigniew Kozłowski,
Milan
the Telerik team
Could you please provide us with more information about your scenario? It might be possible to achieve the goal without even retrieving a reference to a UI row. I am interested to know why it is necessary to access UI rows?
Sincerely yours,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
0

Zbigniew Kozłowski
Top achievements
Rank 1
answered on 04 Oct 2010, 07:48 AM
well i need two things, one is to get object, but i could achive it without a reference to UI, but second thing is to change font weight of current row
0

Zbigniew Kozłowski
Top achievements
Rank 1
answered on 06 Oct 2010, 08:27 AM
so anyone can help me ?
0
Hi Zbigniew Kozłowski,
You can easily bind the FontWeight property of the row to its IsSelected or IsCurrent property. You could try the following approach:
<
my:BoolToFintWeightConverter
x:Key
=
"converter"
/>
<
Style
TargetType
=
"telerik:GridViewRow"
x:Key
=
"rowStyle"
>
<
Setter
Property
=
"FontWeight"
Value="{Binding IsSelected,
RelativeSource={RelativeSource Self},
Converter={StaticResource converter}}"/>
</
Style
>
public
class
BoolToFintWeightConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
var boolValue = (
bool
) value;
if
(boolValue)
{
return
FontWeights.Bold;
}
else
{
return
FontWeights.Normal;
}
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
return
null
;
}
}
The last step is to assign the custom row style to the RowStyle property of the grid.
Hope this helps.
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
0

Steve
Top achievements
Rank 1
answered on 13 May 2014, 07:40 PM
Milan,
It really doesn't matter why one would want to get the GridViewRow, how can you get it?
var selectedRow = (GridViewRow)this.ListGridView.ItemContainerGenerator.ContainerFromItem(this.ListGridView.SelectedItem);
but it works only when grid is not groupped. How can i get GridViewRow from group?
And why does the above return null?
Thanks ahead of time,
Steve
It really doesn't matter why one would want to get the GridViewRow, how can you get it?
var selectedRow = (GridViewRow)this.ListGridView.ItemContainerGenerator.ContainerFromItem(this.ListGridView.SelectedItem);
but it works only when grid is not groupped. How can i get GridViewRow from group?
And why does the above return null?
Thanks ahead of time,
Steve
0
Hello Steve,
One possible reason for the ItemContainerGenerator.ContainerFromItem() method to stop working is for the SelectedItem to be null. You need a SelectedItem otherwise you won't get its container.
Another way to get the grouped row is to check if there are any groups and then use the ChildrenOfType<GridViewRow>() extension method on the GridView to get the selected row container. However, this will only work if the GroupRenderMode is set to Nested (this is the default mode), if its set to Flat you can use the ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) method to get the selected container row container.
For more information about ChildrenOfType() method you can check Easy programmatic UI customization for WPF and Silverlight blog post.
In order to advise you better could you please provide us with more details about your scenario ?
We are looking forward to your response.
Regards,
Boris Penev
Telerik
One possible reason for the ItemContainerGenerator.ContainerFromItem() method to stop working is for the SelectedItem to be null. You need a SelectedItem otherwise you won't get its container.
Another way to get the grouped row is to check if there are any groups and then use the ChildrenOfType<GridViewRow>() extension method on the GridView to get the selected row container. However, this will only work if the GroupRenderMode is set to Nested (this is the default mode), if its set to Flat you can use the ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) method to get the selected container row container.
private
void
Button1_Click(
object
sender, RoutedEventArgs e)
{
var grid =
this
.clubsGrid
as
RadGridView;
if
(grid.GroupCount > 0 && grid.SelectedItem !=
null
)
{
if
(grid.GroupRenderMode == GroupRenderMode.Nested)
{
var groupedRows = grid.ChildrenOfType<GridViewRow>().FirstOrDefault(x => x.IsSelected);
}
else
{
// If GroupRenderMode="Flat" use this
var rowContainer = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem)
as
GridViewRow;
}
}
}
For more information about ChildrenOfType() method you can check Easy programmatic UI customization for WPF and Silverlight blog post.
In order to advise you better could you please provide us with more details about your scenario ?
We are looking forward to your response.
Regards,
Boris Penev
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0

Steve
Top achievements
Rank 1
answered on 14 May 2014, 03:53 PM
Apparently the key was the GroupRenderMode!
Thanks for the quick response,
Steve
Thanks for the quick response,
Steve