We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

datagrid button code behind

I have a button inside a datatemplate of the sfdatagrid that I want to use to activate a detail edit page for the selected record.  Can you show me an example of this using visual basic?

3 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team September 11, 2017 05:06 PM UTC

Hi David, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your query. We couldn’t understand your requirement clearly. So could you please share some more information about your query as like,  
  1. When you select button to enter the edit mode of selected record ?
  2. When you click on the button to navigate the focus to the another window to shows the selected records of DataGrid ?
 
This would be more helpful for us to proceed further. 
 
Regards, 
Muthukumar K 



DG David Gammon September 11, 2017 05:13 PM UTC

#2  When I click the button I want to navigate to another page and display the selected record from the datagrid.



MK Muthukumar Kalyanasundaram Syncfusion Team September 12, 2017 02:44 PM UTC

Hi David, 
 
Thanks for the update. 
 
You can achieve your requirement “to display the selected record from the datagrid when navigating to another page” by binding SelectedItem to TwoWay  to the view model of the navigating page  using  SfDataGrid.SelectedItem property.  Please refer the below code example: 
 
Code Snippet: Xaml 
<syncfusion:SfDataGrid x:Name="dataGrid" 
                        Grid.Row="0" 
                        AutoGenerateColumns="False" 
                        AllowEditing="True" 
                        <!--Binding selected item in grid--> 
                        SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                        ItemsSource="{Binding GDCSource}" 
                        ShowGroupDropArea="True" 
                        ShowRowHeader="True"> 
 
Setting view model as  Datacontext to Navigating page and showing SelectedItem value in TextBlock: 
 
Code Snippet: VB 
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) 
                Dim win As New Window2() 
                win.DataContext = (TryCast(Me.DataContext, PersonModel)).SelectedItem 
                win.Show() 
End Sub 
 
Xaml 
<Grid >        
    <!--Binding LastName of selected items--> 
    <TextBlock HorizontalAlignment="Center"  
                VerticalAlignment="Center" Width="120" Height="50"  Text="{Binding LastName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  /> 
</Grid> 


Please let us know if you have any other questions. 

Regards, 
Muthukumar K 


Loader.
Live Chat Icon For mobile
Up arrow icon