for example: I'm binding the grid datasource to a list of class objects (with 2 properties). I want to use the combo box selection for one of the properties. The item list in the combobox will be populated dynamically during runtime (eg, history).
The problem that I'm having is that when selecting an item from the combo box, and moving away from the cell, the selected value disappears.
// Class field List<string> comboItemSource = new List(); // Constructor public Constructor() { InitializeComponent(); grid.FieldLayouts.Clear(); grid.FieldLayouts.Add(new FieldLayout()); InitGridFields(); // Populate datasource List<dataEntry> datasource = new List<dataEntry>(); datasource.Add(new dataEntry("Test1", "")); datasource.Add(new dataEntry("Test2", "")); datasource.Add(new dataEntry("Test3", "Temp")); datasource.Add(new dataEntry("Test4", "")); datasource.Add(new dataEntry("Test5", "Temp")); grid.DataSource = datasource; } private void InitGridFields() { // Create field // 1st column Field field = new Field(); field.Name = "Name"; grid.FieldLayouts[0].Fields.Add(field); // 2nd column, with combo box selection field = new Field(); field.Name = "Group"; grid.FieldLayouts[0].Fields.Add(field); field.Settings.EditorType = typeof(XamComboEditor); ComboBoxItemsProvider cbip = new ComboBoxItemsProvider(); cbip.ItemsSource = comboItemSource; // Drop down Style style = new Style(typeof(XamComboEditor)); Setter setter = new Setter(); setter.Property = XamComboEditor.ItemsProviderProperty; setter.Value = cbip; style.Setters.Add(setter); // Editable text box setter = new Setter(); setter.Property = XamComboEditor.IsEditableProperty; setter.Value = true; style.Setters.Add(setter); field.Settings.EditorStyle = style; } private void grid_CellUpdated(object sender, CellUpdatedEventArgs e) { string value = e.Record.GetCellText(e.Field); if (!comboItemSource.Contains(value)) { comboItemSource.Add(value); } }
public class dataEntry { public string Name { get; set; } public string Group { get; set; } public dataEntry(string name, string group) { Name = name; Group = group; } }
Please help. Thanks!!
The solution turns out to be fairly simple. In the sample code you posted, the code is assigning a List<string> to the XamComboEditor. List does not notify when it is modified. If you replace List with BindingList, you will get the change notification functionality you need in order to make the binding work correctly.
Replace the List definition for the comboItemSource with the following:
BindingList<string> comboItemSource = new BindingList<string>();
You will need to add the following namespace declaration to the top of the file:
using System.ComponentModel;
This corrects the problem on my machine, Let me know if this works for you.
Thanks
Hello,
I see the problem. Let me check with engineering and get back to you about why this is happening. In the meantime, you can try handling one of the ComboEditor events and then explicitly apply the value to the field.
Thanks,