Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
Help with XamComboEditor and ComboBoxItemsProvider
posted
Hi, I'm having problem with using combo boxes in my XamGrid.

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);
    }
}

and the class definition that I'm using:
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!!

[Edit]
If I were to type in the values and hit return, then the values will stay. However, if I were to select a value from the combo box, then the moment I move out of the cell, the value disappears.