Expand Single Hierarchy Item in RadGridView in Silverlight 5
In this article we would see; how we can expand a single row always (collapse previous expanded) in RadGridView from Telerik in Silverlight 5. RadGridView is blessed with many LOB elegant features. One of them is displaying Parent-Child Data in Hieararchical way.
You need the followings to get this sample working:
- Visual Studio 2010
- Silverlight 5 SDK
- RadControls for Silverlight 5
Go ahead and create a Silverlight project.
As I mentioned in the pre-requisites, we would be using Silverlight 5 to use RadControls for Silverlight 5 from Telerik.
Now, we need to add the following Telerik DLLs, to proceed further.
We would have a RadGridView in our MainPage. You could enable properties based on your choice. I have added a few. As Following:
The ViewModel is responsible for providing data to the View, as follows:
Now we are ready to run the project, if you run; you would see that we have hierarchical records not expanded at all. But when we try to expand, it is available by default for all and you can expand all rows.
So the following is our problem statement.
Well, the solution is very straight forward; you need to subscribe to the RowIsExpandedChanged event of the RadGridView. You could achieve it from the XAML or from the Code-Behind.
Then we would have to have a variable that would contain the current expanded row.
Now, in the event handler for RowIsExpandedChanged, we have to do the following:
We would only check for the row expanded, and if our container is null we would assign the current one; Else, we would make it collapsed and then assign the current one.
Isn’t it simple? Now let’s test the application.
Yes, you can now have the a single expanded row always.
Hope it helps thanks for reading.
Source Code: Click Here
Article as PDF: Click Here
Tryout my Codeplex Projects: