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

Show RowDetails on a button click

5 Answers 406 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richa
Top achievements
Rank 1
Richa asked on 27 Apr 2011, 10:24 AM
I have a datagrid with a select column.
I want to view RowDetails for selected row on the click of a button.
Can you help in implementing this using MVVM pattern?

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 27 Apr 2011, 12:01 PM
Hello Richa,

You may handle the Click event of the button like follows:

private void Button1_Click(object sender, RoutedEventArgs e)
        {
            foreach(Club club in this.clubsGrid.SelectedItems)
            {
                var row = this.clubsGrid.ItemContainerGenerator.ContainerFromItem(club) as GridViewRow;
                row.DetailsVisibility = Visibility.Visible;
            }
        }
 

All the best,
Maya
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
Richa
Top achievements
Rank 1
answered on 02 May 2011, 12:25 PM
Thanks, but i want to implement this using MVVM pattern.
Could you please let me know how will i get the selected row in the grid in my viewmodel?
0
Maya
Telerik team
answered on 02 May 2011, 12:31 PM
Hello Richa,

You may get the SelectedItem of the RadGridView by binding it to a corresponding property in your ViewModel:

MainWindow.xaml
<telerik:RadGridView Name="clubsGrid"
                             ItemsSource="{Binding Clubs}"
                             AutoGenerateColumns="False"
                 SelectedItem="{Binding SelectedItem}">
 
 
MyViewModel.cs:
    private object selectedItem;
        public object SelectedItem
        {
            get { return this.selectedItem; }
            set
            {
                if (value != this.selectedItem)
                {
                    this.selectedItem = value;
                    this.OnPropertyChanged("SelectedItem");
                }
            }
        }
 
However, the corresponding row and the row details are visual elements and will be breaking the concept of MVVM to work with the visual elements in your ViewModel. 

Kind regards,
Maya
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
Richa
Top achievements
Rank 1
answered on 02 May 2011, 01:02 PM
For showing the row details on a button click i need the reference of the grid in the viewmodel.
Can you please tell how will i get the reference of the grid in viewmodel?
0
Maya
Telerik team
answered on 02 May 2011, 01:12 PM
Hi Richa,

As mentioned previously getting access of the visual elements and working with them in your ViewModel contradicts to the concept of Model-View-ViewModel design pattern. May you share a bit more details why handling the Click event of a button is not appropriate for your scenario ?
 

Greetings,
Maya
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
Tags
GridView
Asked by
Richa
Top achievements
Rank 1
Answers by
Maya
Telerik team
Richa
Top achievements
Rank 1
Share this question
or