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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Template column - How to get one cell's value ?

Thread ID:

Created:

Updated:

Platform:

Replies:

125225 Aug 1,2016 08:50 AM UTC Aug 4,2016 02:37 PM UTC WPF 3
loading
Tags: SfDataGrid
Yasahbi
Asked On August 1, 2016 08:50 AM UTC

Hi !
I use a SfDataGrid and i have 2 template column with pickers.
The problem is that i don't know how to get the selected value of these pickers in my viewModel 
Any one can help me ? Thanks ! :)

Here's my code : 

<?xml version="1.0" encoding="utf-8" ?>
<controls:KerhisContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                            x:Class="Kerhis.Domopig.View.Views.MouvementAnimauxPage"
                            x:Name="this"
                            xmlns:controls="clr-namespace:Kerhis.Core.Forms.Controls;assembly=Kerhis.Core.Forms"
                            xmlns:cr="clr-namespace:Kerhis.Domopig.View.Controls;assembly=Kerhis.Domopig.View"
                            xmlns:syncfusion="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms"
                            BindingContext="{Binding MouvementAnimaux, Source={StaticResource Locator}}"
                            Title="Mouvements Animaux">
  
  <controls:KerhisContentPage.Content>
    <ScrollView>
      <StackLayout VerticalOptions="FillAndExpand">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
      
        <Image Source="salle.png" Grid.Column="0" Grid.Row="0"/>
        <Label Text="Nom de la salle : " FontSize="Medium" HorizontalOptions="Start" VerticalOptions="Center" Grid.Column="1" Grid.Row="0"/>
        <Label Text="{Binding Salle.LibelleSalle}" FontSize="Medium" HorizontalOptions="Start" VerticalOptions="Center" Grid.Column="2" Grid.Row="0"/>
        <Label Text="Batiment : " FontSize="Medium" HorizontalOptions="End" VerticalOptions="Center" Grid.Column="3" Grid.Row="0"/>
        <Label Text="{Binding Salle.Batiment.LibelleBatiment}" FontSize="Medium" HorizontalOptions="Start" VerticalOptions="Center" Grid.Column="4" Grid.Row="0"/>
        <Label Text="Site : " FontSize="Medium" HorizontalOptions="End" VerticalOptions="Center" Grid.Column="5" Grid.Row="0"/>
        <Label Text="{Binding Salle.Site.LibelleSite}" FontSize="Medium" HorizontalOptions="Start" VerticalOptions="Center" Grid.Column="6" Grid.Row="0"/>

        <Image Source="cochon.png" Grid.Column="0" Grid.Row="1"/>
        <Label Text="{Binding NombreAnimaux}" FontSize="Medium" HorizontalOptions="Start" VerticalOptions="Center" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>

      </Grid>
    
      <cr:KerhisDataGrid AutoGenerateColumns="False"
                         ItemsSource="{Binding ListeMouvementAnimaux}"
                         ColumnSizer="Star"
                         SelectionMode="SingleDeselect"
                         VerticalOptions="FillAndExpand">

        <cr:KerhisDataGrid.Columns x:TypeArguments="syncfusion:Columns">
          <syncfusion:GridTextColumn HeaderText="Date"
                                     MappingName="DateMouvement"
                                     TextWrapping="WordWrap"/>
        
          <syncfusion:GridTextColumn HeaderText="Effectif J-1"
                                     MappingName="AncienEffectif"
                                     TextWrapping="WordWrap"/>

          <syncfusion:GridTextColumn HeaderText="Effectif J-J"
                                     MappingName="EffectifActuel"
                                     TextWrapping="WordWrap"/>

          <syncfusion:GridTextColumn HeaderText="Différence"
                                     MappingName="Difference"
                                     TextWrapping="WordWrap"/>

          <syncfusion:GridTemplateColumn HeaderText="Qualification"
                                     MappingName="CodeQualificationMouvement"
                                     TextWrapping="WordWrap">
            
            <syncfusion:GridTemplateColumn.CellTemplate>
              <DataTemplate>
                <controls:KerhisPicker HorizontalOptions="FillAndExpand"
                                       ItemsSource="{Binding BindingContext.Qualifications, Source={x:Reference this}}"
                                       VerticalOptions="Center"/>
              </DataTemplate>
            </syncfusion:GridTemplateColumn.CellTemplate>
          </syncfusion:GridTemplateColumn>

          <syncfusion:GridTemplateColumn HeaderText="N° Bon Uniporc associé"
                                     MappingName="IDBordereau"
                                     TextWrapping="WordWrap">
            
            <syncfusion:GridTemplateColumn.CellTemplate>
              <DataTemplate>
                <controls:KerhisPicker HorizontalOptions="FillAndExpand"
                                       ItemsSource="{Binding BindingContext.ListeBordereaux, Source={x:Reference this}}"
                                       VerticalOptions="Center"
                                       IsEnabled="{Binding BindingContext.Enabled, Source={x:Reference this}}"/>
              </DataTemplate>
            </syncfusion:GridTemplateColumn.CellTemplate>
          </syncfusion:GridTemplateColumn>

          <syncfusion:GridTextColumn HeaderText="Commentaire"
                                     MappingName="Commentaire"
                                     TextWrapping="WordWrap"/>

        </cr:KerhisDataGrid.Columns>

      </cr:KerhisDataGrid>
    </StackLayout>
    </ScrollView>
  </controls:KerhisContentPage.Content>
</controls:KerhisContentPage>

Jai Ganesh S [Syncfusion]
Replied On August 2, 2016 01:37 PM UTC

Hi Yasahbi, 
 
You can get the selectedvalue for the control that is defined inside the Templatecolumn by using the following code, 
 
<Syncfusion:GridTemplateColumn  MappingName="EmployeeArea" Width="200" Syncfusion:FocusManagerHelper.WantsKeyInput="True" AllowFiltering="True"> 
           <Syncfusion:GridTemplateColumn.CellTemplate> 
                 <DataTemplate> 
                        <ListBox Width="200" Height="24" Syncfusion:FocusManagerHelper.FocusedElement="True" ItemsSource="{Binding Path=DataContext.ListItems,ElementName=datagrid}" SelectedValue="{Binding Path=DataContext.SelectedValue,ElementName=datagrid}"/> 
                 </DataTemplate> 
        </Syncfusion:GridTemplateColumn.CellTemplate> 
                  
   </Syncfusion:GridTemplateColumn> 
 
In the above sample, we have load the ListBox inside the GridTemplateColumn, and get its SelectedValue from viewmodel by binding viewmdel property. 
 
Or else if you want to bind the underlying collection property inside the GridTemplateColumn by using the following code, 
 
<Syncfusion:GridTemplateColumn MappingName="EmployeeAge" AllowFiltering="True"> 
                     
      <Syncfusion:GridTemplateColumn.CellTemplate> 
                 <DataTemplate> 
                       <TextBlock Text="{Binding EmployeeAge}"/> 
                  </DataTemplate> 
      </Syncfusion:GridTemplateColumn.CellTemplate> 
                     
 </Syncfusion:GridTemplateColumn> 
 
 
Regards, 
Jai Ganesh S 


Yasahbi
Replied On August 3, 2016 07:44 AM UTC

Hi Jai ! 
Thanks for answeringbut it doesn't resolve my problem.
The important part of my code is the following one : 

<syncfusion:GridTemplateColumn HeaderText="N° Bon Uniporc associé"
                                     MappingName="IDBordereau"
                                     TextWrapping="WordWrap">
            
            <syncfusion:GridTemplateColumn.CellTemplate>
              <DataTemplate>
                <controls:KerhisPicker HorizontalOptions="FillAndExpand"
                                       ItemsSource="{Binding BindingContext.ListeBordereaux, Source={x:Reference this}}"
                                       VerticalOptions="Center"
                                       IsEnabled="{Binding BindingContext.Enabled, Source={x:Reference this}}"/>
              </DataTemplate>
            </syncfusion:GridTemplateColumn.CellTemplate>
          </syncfusion:GridTemplateColumn>

As you can see, i use a Picker in a column, the problem is that i do'nt know how to get the selected value, because the Picker hasn't a SelectedValue Property.

Jai Ganesh S [Syncfusion]
Replied On August 4, 2016 02:37 PM UTC

Hi Yasahbi,  
 
As we said in our previous update, you can bind the underlying class property or the viewmodel property inside the TemplateColumn. But in your code snippet, you have used the custom picker inside the TemplateColumn. In this case you have to write the SelctedValue property in custom picker and get the value from viewmodel through binding. 
 
Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;