Articles in this section
Category / Section

Change selected index of one picker in other pickers selection changed event in DataGrid.

1 min read

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

 

Conclusion

I hope you enjoyed learning about how to change selected index of one picker in other pickers selection changed event in DataGrid.

You can refer to our  Xamarin.Forms DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our  Xamarin.Forms DataGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied