Hi,
I tried to follow Tacho's example.
So far I managed to show a ComboBoxEditor in a field with correct data. But once a new items is selected the editor sets the item, but as soon as the editing is finished the item is set to null.
What am I doing wrong ?
<igDp:XamDataGrid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" DataSource="{Binding Path=ActiveClass.Students}" VerticalAlignment="Stretch"> <igDp:XamDataGrid.FieldLayouts> <igDp:FieldLayout> <igDp:Field Name="Id" Label="Id"/> <igDp:Field AlternateBinding="{Binding Path=Gender.Name}" BindingType="Unbound" Label="Gender"> <igDp:Field.EditorStyle> <Style TargetType="editors:XamComboEditor"> <Setter Property="ItemsSource" Value="{Binding Source={StaticResource GenderCollection}}" /> <Setter Property="DisplayMemberPath" Value="Name"/> <Setter Property="SelectedItem" Value="{Binding Path=DataItem.Gender, Converter={StaticResource GenderObjectToGenderViewModelConverter}, ConverterParameter={StaticResource GenderCollection}}" /> </Style> </igDp:Field.EditorStyle> </igDp:Field> <igDp:Field Name="Age" Label="Age"/> <igDp:Field Name="Name" Label="Name" /> </igDp:FieldLayout> </igDp:XamDataGrid.FieldLayouts> </igDp:XamDataGrid>
I have attached the project. (Not really allowed to attach the project of 2MB here, https://we.tl/t-tv4yqt7oWI )
Thanks in advance
Nice. Just the solution to a problem I am looking at.
Thanks for your reply. There should be two ways to address this.
1. Use Name bindings instead of AlternateBinding
2. Incorporate the use of referring to the DataType property.
I attached both approaches below. Let us know if you have any questions.
NameBinding.rar
DataType.zip
Hello Michael,
Thanks for the reply.
The Converter should take care of the mismatching types. But alright, we will not use the converter and make it work this way.
However the example you provided does simple not change the Gender object on the students. It does on the UI, but not in the collection. To demonstrate this I have added a button which shows the Genders of each student in the collection. You can try to change the gender in the Grid and press the button, nothing has changed.
And to demonstrate further what I want from XamComboEditor I have added a normal DataGrid to the solution with a normal DataGridComboBoxField which works flawlessly.
Can we add such behavior to the XamComboBoxEditor ?
InfragisticsExampleWithListInsteadOfObservableCollection.rar
Hello,
This isn't an issue with the combo or the grid, merely mismatching types between the field and combo's itemsource.
I attached a modified sample that is more aligned to your requirement below that addresses this concern. The sample also uses our ComboBoxField and FieldBinding functionality, improvements added over the years. Please let us know if you have any questions.
InfragisticsExampleWithListInsteadOfObservableCollection.zip
Hello Divya,
Thank for your reply and effort, but unfortunately this will not work in the real world. Let me explain what you are trying to do, and hopefully you can see how wrong that is.
Instead of changing the Gender object of the student you are changing the name of the gender object. This will be like a school had a student registered wrongly as a female and they wanted to change it to male, but instead give the student new cloths so he would look like a female instead.
Btw, my question is not about finding a solution for my project, I can do that myself. My question is why does the ComboBoxEditor behave like that. First it can figure out about the DisplayMemberPath, which correctly shows the Name property, but afterwards it cannot and tries to use the ToString() method of the Object.