Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am working on mvvm application, in which i have bind the datagrid. in the datagrid bind the combobox, which is bind with different datasource, i want to add selection changed event for that combobox. and how to find the selectedvalue of that combobox with row id of the data grid.
i have tried below code:
xaml code:
XML
<DataGridTemplateColumn MinWidth="100" Header="Grade Scenario" >
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <ComboBox DisplayMemberPath="GradeScenarioID"   SelectedValuePath="GradeScenarioID" ItemsSource="{Binding Path=DataContext.GradeScenarioData, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" >
                                    </ComboBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>


What I have tried:

viewmodel code:
C#
 public ObservableCollection<assetsubclass> AssetSubClassData
       {
           get
           {
               return _assetSubClassData;
           }
           set
           {
               _assetSubClassData = value;
               RaisePropertyChanged("AssetSubClassData");
           }
       }


private async void AssetClassSelectionChanged(RoutedEventArgs e)
       {
           try
           {
               Messenger.Default.Send<bool>(true, BroadcastMessageToken.ShowBusyIndicator);
               if (!string.IsNullOrWhiteSpace(ClassID))
               {
                   var assetSubClasses = await _dataService.GetCollectionByParentId<assetsubclass>(ClassID);
                   if (assetSubClasses != null)
                   {
                       AssetSubClassData = new ObservableCollection<assetsubclass>(assetSubClasses.ToList());
                   }
               }
               var gradeScenario = await _dataService.GetCollection<data.sql.gradescenario>();
               if (gradeScenario != null)
               {
                   GradeScenarioData = new ObservableCollection<data.sql.gradescenario>(gradeScenario.ToList());
               }
           }
           catch (Exception ex)
           {
               ExceptionDetails(ex);
           }
           finally
           {
               Messenger.Default.Send<bool>(false, BroadcastMessageToken.ShowBusyIndicator);
           }
       }
Posted
Updated 4-May-16 0:19am
v4
Comments
CHill60 4-May-16 6:23am    
Changing the selection on the combobox is a UI function - try using the SelectedCellsChanged event on the DataGrid - the sender and args parameters will give you enough information to determine the row number

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900