ComboBoxCell binding

Anyone have an example of property binding for a ComboBoxCell? I have a constant list of possible string values, and I’m trying to bind the actual value to a class property (e.g. below). (As an aside, what I really want is a dropdown (not a combobox), but I don’t see this option for cells.)

public class MyItem : TreeGridItem
{
   public string Value { get; set; }
}

public class MyTree : TreeGridView
{
   public MyTree
   {
      var cbox = new ComboBoxCell 
      { 
          DataStore = new List<string> { "val 1", "val 2", "val 3" },
          // how to bind selected value to MyItem.Value?
      };
      var column = new GridColumn 
      { 
          Editable = true, 
          DataCell = cbox 
      };
      Columns.Add(column);

      var collection = new TreeGridItemCollection();
      collection.Add(new MyItem { Value = "val 2" });
   }
}

Thanks,

Jon

Hey @sarg,

Sorry for the late response! You need to use the ComboBoxCell.Binding property like so:

  var cbox = new ComboBoxCell 
      { 
          DataStore = new List<string> { "val 1", "val 2", "val 3" },
          Binding = Binding.Property<MyItem>(m => m.Value)
      };

Hope this helps.
Curtis

1 Like