Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Datagrid and DatagridComboBoxColumn

$
0
0

Hi, I have DataGrid with ItemSource binded to Observerablecollection of users. So each row of datagrid contains one object of type User.I would also likefor each row add another column of type DataGridComboBoxColumn enabling selection of user from anotherObserverableCollection containing all existing users. So when an user selects an user in DataGridComboBoxColumn then selected user is moved to ObserverableCollection which is binded as itemsource for DataGrid. But i cannot figure it out :-(

<DataGrid HeadersVisibility="None"  CanUserSortColumns="False" CanUserResizeRows="False"  Name="dgPlayers" Width="auto" CanUserAddRows="{Binding Path=TeamIsNotFull}"      GridLinesVisibility="Horizontal"  AutoGenerateColumns="False"  ItemsSource="{Binding Path=Players}"><DataGrid.Columns><DataGridComboBoxColumn Width="125" DisplayMemberPath="DisplayedName"   Header="Hráč" SelectedItemBinding="{Binding Path=. }">                                                               <DataGridComboBoxColumn.ElementStyle><Style TargetType="ComboBox"><Setter Property="ItemsSource" Value="{Binding ElementName=MainGrid, Path=DataContext.AvailablePlayers}"/></Style> </DataGridComboBoxColumn.ElementStyle><DataGridComboBoxColumn.EditingElementStyle><Style TargetType="ComboBox"><Setter Property="ItemsSource" Value="{Binding ElementName=MainGrid, Path=DataContext.AvailablePlayers}"/></Style></DataGridComboBoxColumn.EditingElementStyle></DataGridComboBoxColumn><DataGridTextColumn Header="Přezdívka" Binding="{Binding Mode=OneWay}" />                                    </DataGrid.Columns></DataGrid>

This code does not work properly because binding on this page is bad:

SelectedItemBinding="{Binding Path=. }"> 

When i use only SelectedItemBinding="{Binding}">  exception is thrown

"Two-way binding requires Path or XPath."



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>