I am pretty new to WPF and I am stuck on this one, I couldn't find anything that helped me solve my problem.
I am trying to create DataGrid where I would like to compare multpiple people from imported file to people in database. My idea of that was creating told DataGrid (of person data) with ComboboxColumn (with list of people from database). My main problem is that both people to compare and to fill combobox, may differ because of user choice in previous window. Having some database work I save both choices in Window_Loaded as:
personList //list of Person objects to populate combobox
pisList //list of Person objects to fill DataGrid
Now I have no idea how to get both those values to DataGrid so I populate ComboboxColumn as well. I tried do get one of those Values as DataContext od whole Window and second as datagrid ItemsSource.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Database db = new Database();
List<Person> personList = (...);
List<Person> pislist = (...);
dgPlayers.ItemsSource = impTeam.PlaysInSquad.ToList();
wPlayers.DataContext = personList;
}
As I failed miserably to get those 2 in one DataGrid, I created 2 separate, but still can make it work.
<DataGrid Name="dgPlayers" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Number" Binding="{Binding Number}" IsReadOnly="True"/>
<DataGridTextColumn Header="Name" Binding="{Binding Person.Name}" IsReadOnly="True"/>
<DataGridTextColumn Header="Surname" Binding="{Binding Person.Surname}" IsReadOnly="True"/>
<DataGridTextColumn Header="Role" Binding="{Binding IDRole}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
<DataGrid Name="dgList" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="List" ItemsSource="{Binding DataContext.Person}" DisplayMemberPath="Name"/>
</DataGrid.Columns>
</DataGrid>
First DataGrid is ok, but still, I can't properly populate ComboboxColumn + I would love to see that in one DataGrid instead of two.
EDIT
Even though I already tried it before without success, solution from this thread worked for me after like 3rd try: How to Bind data to DataGridComboBoxColumn in DataGrid using MVVM