How to change selected index of one picker in other picker's selection changed event in .NET MAUI DataGrid(SfDataGrid)?
You can change the selected index of one picker in a grid column by altering the selected index of another picker in a different grid column. This is achieved by binding a common property to the SelectedIndex property of both the pickers in the .NET MAUI DataGrid.
<syncfusion:SfDataGrid ItemsSource="{Binding OrdersInfo}"
AutoGenerateColumnsMode="None"
ColumnWidthMode="Auto"
DefaultColumnWidth="155">
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTemplateColumn MappingName="Order ID">
<syncfusion:DataGridTemplateColumn.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>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
<syncfusion:DataGridTemplateColumn MappingName="Employee ID ">
<syncfusion:DataGridTemplateColumn.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>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
<syncfusion:DataGridTextColumn MappingName="CustomerID"
HeaderText="Customer ID" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
EmployeeViewModel.cs
private int[] FirstPickerItems = new int[] { 0, 1, 2, 3, 4, 5, 6 };
private int[] SecondPickerItems = new int[] { 1500, 1501, 1502, 1503, 1504, 1505, 1506 };
private ObservableCollection<int> firstPickerItem;
public ObservableCollection<int> FirstPickerItem
{
get { return firstPickerItem; }
set
{
this.firstPickerItem = value;
OnPropertyChanged("FirstPickerItem");
}
}
private ObservableCollection<int> secondPickerItem;
public ObservableCollection<int> SecondPickerItem
{
get { return secondPickerItem; }
set
{
this.secondPickerItem = value;
OnPropertyChanged("SecondPickerItem");
}
}
Output
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to change the selected index of one picker in another picker’s selection changed event in DataGrid.
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!