)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change selected index of one picker in other pickers selection changed event in SfDataGrid?

Platform: Xamarin.Forms |
Control: SfDataGrid |
Published Date: February 15, 2017 |
Last Revised Date: January 2, 2020
Tags: selection

You can change the selected index of one picker in a grid column by changing the selected index of other picker in another grid column by binding a common property to the SelectedIndex property of both the pickers.

<sfgrid:GridTemplateColumn MappingName="OrderId" >
   <sfgrid:GridTemplateColumn.CellTemplate>
       <DataTemplate>
            <Picker TextColor="Black" 
                          ItemsSource="{Binding  Source={x:Reference viewModel},Path=  FirstPickerItem}"
                          SelectedIndex="{Binding Source={x:Reference viewModel},Path= Selectedindex, Mode=TwoWay}">
                  </Picker>
              </DataTemplate>
       </sfgrid:GridTemplateColumn.CellTemplate>
   </sfgrid:GridTemplateColumn>
 
 <sfgrid:GridTemplateColumn MappingName="EmployeeID " >
    <sfgrid:GridTemplateColumn.CellTemplate>
         <DataTemplate>
             <Picker TextColor="Black"
                           ItemsSource="{Binding  Source={x:Reference viewModel},Path=  SecondPickerItem}"
                             SelectedIndex="{Binding  Source={x:Reference viewModel},Path= Selectedindex, Mode=TwoWay}">
                 </Picker>
               </DataTemplate>
     </sfgrid:GridTemplateColumn.CellTemplate>
</sfgrid:GridTemplateColumn>

 

ViewModel.cs

private int selectedindex;
private  int[] FirstPickerItems = new int[] { 0,1, 2, 3, 4, 5, 6 };
private int[] SecondPickerItems = new int[] { 1500, 1501, 1502, 1503,1504, 1505, 1506 };
 
public ViewModel()
{
     Selectedindex = 1;
}
 
public int Selectedindex
{
     get
     {
        return selectedindex;
     }
     set
     {
         selectedindex = value;
         RaisePropertyChanged("Selectedindex");
     }
}
 
 
public ObservableCollection<int> FirstPickerItem
{
            get { return firstPickerItem; }
            set
            {
                this.firstPickerItem = value;
                RaiseCollectionChanged("FirstPickerItem");
            }
 }
 
public ObservableCollection<int> SecondPickerItem
 {
            get { return secondPickerItem; }
            set
            {
                this.secondPickerItem = value;
                RaiseCollectionChanged("SecondPickerItem");
            }
 }

 

Screenshot

 

Image for change selected index of one picker in other pickers selection changed event

 

Sample Link

https://www.syncfusion.com/downloads/support/directtrac/general/ze/PickerSelectedIndexKB-1768951083.zip

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon