I have a DataGrid. Let it have two columns name and Gender :
<DataGrid............>
<DataGridTemplateColumn Header="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Name, RelativeSource.........}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Age">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox SelectedItem="{Binding Selected, RelativeSource.........}" >
<sys:String> Male </sys:String>
<sys:String> Female </sys:String>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid>
Now When I run the program, and suppose I have 5 rows in the DataGrid, thenwhen I select male in any row e.g. 3rd row, then all the combobox's SelectedItem becomes Male. How can I avoid this?
When my program runs I have only 1 row, But when I add more rows it looks like :
When I try to select Female in any ComboBox :
When I select Female in any ComboBox :
I know that my Binding is Incorrect, so I am facing such a problem, but can anybody explain me the ComboBox's SelectedItem Binding inside a DataGrid?
SelectedItem
binding? And what is theItemsSource
of the DataGrid? – vadimSelected
property resides where? – Rohit VatsSelected
Property resides inGroupsViewModel
. – Vishal