Click here to Skip to main content
14,733,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello dear readers,

I have the following problem:

I have a view and on that view I placed a DataGrid. I connected the ItemsSource of the DataGrid via Binding to a Property in the ViewModel. It works fine.
There is one Column that I want to show as ComboBoxColumn because the User shall have an amount of data to put in this column. The question is, how can I set the ItemsSource to a List that is not part of the ItemsSource I connected the DataGrid to?

Here some code i used:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Bikes}">
   <DataGrid.Columns>
      <DataGridTextColumn Header="Manufacturer" Binding="{Binding Manufacturer}">
      </DataGridTextColumn>
               
      <DataGridComboBoxColumn Header="Choice" SelectedItemBinding="{Binding Owner}"

         ItemsSource="{Binding Persons}">
      </DataGridComboBoxColumn>
   </DataGrid.Columns>
</DataGrid>


I think I know that this solution is not working because since the ItemsSource of the DataGrid is set to Bikes the ItemsSource of the ComboBoxColumn looks into the objects in Bikes and searches for a Property Persons.
But Persons is another List that is created in the ViewModel.

I really cannot figure out how to set the databinding of the ComboBox in the correct way.

I hope that anyone can help with that. If you need further information please let me know.

Have a good one everybody.
Posted

1 solution

After another hour of research I tried the code from this http://stackoverflow.com/a/5409984[^]

AND IT WORKED :).
   

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