How to Get value as object from selected Rows in MVVM pattern and Pass it window to another window?

Dear admin,

I am newbie to your controls. i am wondering about your wpf  controls. Now i struggled  while passing selected values to one window to another window  just like an object.
Lets assume i have a collection of student information ie, Name, RollNumber, Father Name, Mother Name, etc,. Now i displayed list of students in StudentDisplay window using  sfdatagrid control. Now i want to pass single Student Information  to another StudentInformation Window using selected row values . How can i achieve this using MVVM patern. Could you provide samples.?

Thanks and Regards,
Gowthaman.D

  

3 Replies

DY Deivaselvan Y Syncfusion Team October 3, 2018 03:47 AM UTC

Hi Gowthaman, 

Thank you for contacting Syncfusion support.

 
We have analyzed your query “To pass Selected rows values to another window” and you can achieve your requirement by maintaining a property in viewmodel as like below code snippet 

C#: 
private object selectedItem; 
public object SelectedItem 
{ 
     get 
     { 
          return selectedItem; 
     } 
     set 
     { 
          selectedItem = value; 
          RaisePropertyChanged("SelectedItem"); 
     } 
} 

var window1 = new Window1(); 
window1.DataContext = this.DataContext; 
window1.Show(); 

XAML: 
<Syncfusion:SfDataGrid 
            x:Name="sfdatagrid" 
            SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
            ItemsSource="{Binding EmployeeDetails}"> 

Please find sample for the same from below link and let us know if this helps you 
Sample Link: 

Regards, 
Deivaselvan 



GO GOWTHAMAN October 3, 2018 05:07 AM UTC

Thank You Deivaselvan. But  I need Improved answers. Here you are using button click event so you can easily create an instance for window, while using ICommand for command button to trigger, unable to pass objects for Viewmodel.


DY Deivaselvan Y Syncfusion Team October 3, 2018 05:43 PM UTC

Hi Gowthaman,

Thank you for the update.

You can pass objects using CommandParameter for Button command to ViewModel as like below code snippet 

 
<Syncfusion:SfDataGrid  
            x:Name="sfdatagrid"  
            SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
            ItemsSource="{Binding EmployeeDetails}">  
</Syncfusion:SfDataGrid>  
  
<Button Content="GetSelectedItem" Command="{Binding ButtonCommand}" CommandParameter="{BindingElementName=sfdatagrid}"/>  

Please find modified sample from the below link and let us know if this helps you

Sample Link :
http://www.syncfusion.com/downloads/support/forum/140132/ze/WPF-1138707109

Regards,
Deivaselvan 


Loader.
Up arrow icon