Hi,
My question is similar to the question on this thread https://ko.infragistics.com/community/forums/t/34846.aspx.
I studied the sample code sample download from the thread and applied it to my solution with changes to obsoleted segments and I cant get it to work. The comboboxes are not showing up. Please help.
Here is my code
<igDP:Field BindingType="UseAlternateBinding" AlternateBinding="{Binding Path=SelectedCity, Mode=TwoWay}" Label="{x:Static localization:ManagerParameters.ModificationLabel}" Visibility="Visible"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding DataPresenter.DataContext.Cities}"/> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Thanks,
Lala
Hello Lala,
In order to keep in sync all properties for the SelectedCity with the ones from the editor's item, I can suggest you disable the automatic generation of the fields and manually define them by explicitly setting the alternate binding paths. Setting the SelectedItem property of the editor would be needed as well since we are working with the actual underlying data.
XAML:
<igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /></igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayout.Fields> <igDP:Field Name="Name" /> <igDP:ComboBoxField Name="Cities" AlternateBinding="{Binding Path=SelectedCity, Mode=TwoWay}"> <igDP:ComboBoxField.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding DataItem.Cities, Mode=TwoWay}" /> <Setter Property="DisplayMemberPath" Value="CityName" /> <Setter Property="SelectedItem" Value="{Binding DataItem.SelectedCity, Mode=TwoWay}" /> </Style> </igDP:ComboBoxField.EditorStyle> </igDP:ComboBoxField> <igDP:TextField Name="SelectedCity" AlternateBinding="{Binding Path=SelectedCity.CityName, Mode=TwoWay}" /></igDP:FieldLayout.Fields>
I have attached a sample application that demonstrates the approach from above.
If you have any questions, please let me know.
I have changed the sample you provided. I have added a class City
public class City { public string CityName { get; set; }
public string CityCode { get; set; } }
Changed MyClass
public class MyClass : INotifyPropertyChanged {
private string name; public string Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); } }
private ObservableCollection<City> cities; public ObservableCollection<City> Cities { get { return cities; } set { cities = value; NotifyPropertyChanged("Cities"); } }
private City selectedCity; public City SelectedCity { get { return selectedCity; } set { selectedCity = value; NotifyPropertyChanged("SelectedCity"); } }
}
ViewModel constructor
public ViewModel() { var cities1 = new ObservableCollection<City>(); cities1.Add(new City{CityName = "LA", CityCode = "12345"}); cities1.Add(new City{CityName = "Chicago", CityCode = "23456"});
var cities2 = new ObservableCollection<City>(); cities2.Add(new City { CityName = "LA", CityCode = "02345" }); cities2.Add(new City { CityName = "Chicago", CityCode = "03456" });
collection = new ObservableCollection<MyClass>() { new MyClass(){ Name="US", Cities = cities1, SelectedCity=cities1[0]}, new MyClass(){ Name="GB",Cities= cities2, SelectedCity=cities2[0]} }; }
Xaml
<igDP:ComboBoxField Label="Cities Combo" BindingType="Unbound" AlternateBinding="{Binding Path=SelectedCity, Mode=TwoWay}"> <igDP:ComboBoxField.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding DataItem.Cities, Mode=TwoWay}"/> <Setter Property="DisplayMemberPath" Value="CityName"/> </Style> </igDP:ComboBoxField.EditorStyle> </igDP:ComboBoxField>
When I select a different item from the drop down Cities, the new Selected City is not getting set.
Thank you for the feedback.
In order to bind the SelectedCity property to the selection in the XamComboEditor, I can suggest you use an alternate binding for the unbound field. This way the respective cell for every DataRecord will be bound to the underlying SelectedCity property.
The reason the SelectedItem property of the XamComboEditor becomes null when opening and closing the dropdown when a setter for the SelectedItem is used (instead of the alternate binding) is because the cell itself does not have an underlying value that it is bound to and this leads to inconsistancy between the cell and the editor.
I have figured the SelectedItem. There is one issue I couldnt figure out. I set a default from the list to the SelectedItem. When the application launches, the combobox field is populated with the default selectedItem but when I click on the combobox once, the combobox drops down, when I click again it collapses (as expected) but the SelectedItem ibecomes null (Undesired behaviour). I want it to show the default item. What I can I do to fix this behaviour?
Thanks Tacho, I also need to the selected item of the combobox item.