This is what I have:
public class ViewModel { public BindingList<Row> Rows { get; set; } public BindingList<MyElement> Selectables { get; set; } } public class Row { public MyElement Selected { get; set; } } public class MyElement { public string Value { get; set; } public string Friendly { get; set; } }
This is what I want: XtraGrid with a column that has a combobox editor in each cell. The values ββof the dropdown parameters are different for different lines. In particular, the available options are subsets of ViewModel.Selectables ; the subset is determined by business servers at runtime.
Here is how I am trying to do this:
I create three BindingSources
viewModelBindingSource : with DataSource = ViewModel
rowsBindingSource : with DataSource = viewModelBindingSource AND DataMember = Rows
selectablesBindingSource with DataSource = viewModelBindingSource AND DataMember = Selectables
I set the DataSource grid to rowsBindingSource . I am creating an in-place editor repository for LookupEdit in the grid. I set repositoryItemLookUpEdit DataSource to selecteablesBindingSource I set repositoryItemLookUpEdit as the ColumnEdit value of the column
I connect to gridViews ShownEditor event:
this.gridView1.ShownEditor += gridView1_ShownEditor;
In the gridView1_ShownEditor(object sender, EventArgs e) method, I can then reference the view so that I can do something like this:
GridView view = sender as GridView; var newSelectables = new BindingList<MyElement>(); // businesslogic to populate newSelectables ... var bs = new BindingSource(newSelectables, ""); edit = (LookUpEdit)view.ActiveEditor; edit.Properties.DataSource = bs;
This works to the extent that I get the new parameters in brackets with a click, and selecting an option sets a value for the associated object, i.e. Row.Selected .
And now to my problem, when a cell loses focus, the contents of the cell become empty .
This is apparently due to the fact that I am creating a new BindingSource with a new one, because if I omit this DataSource change, the values ββin ViewModel.Selectables are used instead and it works as expected.
So, does anyone know why the text displayed in the cell disappears after it loses focus in this case?