winformslinq-to-entitiesdevexpressxtragridinplace-editing

problems setting XtraGrid with in-place editor-s (using GridLookUpEdit)


I need an XtraGrid control that has GridLookupEdit to enter column values.

What I managed to do so far:

1) I have configured XtraGrid control

columns: ID, Name, Number
in-place GridLookUp Editors for Name and Number columns

2) on the form Load event I load data from database and set XtraGrid datasource and both repositoryItem(..) datasource, valuemember and displaymember

a) Data are loaded in XtraGrid, I can activate cell but can not choose values from dropdown (from repositoryItem(..)) or enter values manually (i can activate cell in "*" new row but it has the same problem - can not choose from the dropdown or enter values manually) => why?

b) If I don't set datasource for XtraGrid, then both dropdown's are active and i can select values using GridLookupEdit, but when i exit the cell, the cell gets cleared => i believe this is because in this case no xtraGrid.DataSource is set?

        var model = (from TableA a in _dbE.TableA select new {ID, Name, Number}).ToList();

        //if i comment this line out, then i can choose values from GridLookUpEdit
        gridControl1.DataSource = model; 

        repositoryItemNosaukums.DataSource = model;
        repositoryItemNosaukums.ValueMember = "ID";
        repositoryItemNosaukums.DisplayMember = "Name";

        repositoryItemPieteikumaNr.DataSource = model;
        repositoryItemPieteikumaNr.ValueMember = "ID";
        repositoryItemPieteikumaNr.DisplayMember = "Number";

What am I missing?


Solution

  • The problem was, that my data source "model" was a List, but it should have been BindingList with properties AllowNew==True and AllowEdit==True.

    After DevExpress support asked if the data source is read only, i found this post which finally opened my eyes:

    A Problem in DataGridView : datagridview seems readonly to user (WinForms)

    correct version of code

        //no projections (select new ...) for IBindingList<T>..
           //var model = (from TableA a in _dbE.TableA select new {ID, Name, Number}).ToList();
        var model = (from TableA a in _dbE.TableA).ToList(); 
    
        //convert to BindingList
        var bindingModel= new BindingList<TableA>(model);
        bindingModel.AllowNew=true;
        bindingModel.AllowEdit=true;
    
        //bind BindingList to datagrid
        gridControl1.DataSource = bindingModel; //model; 
    
        //... no changes to repositoryItem(..) stuff
        repositoryItemNosaukums.DataSource = model;
        repositoryItemNosaukums.ValueMember = "ID";
        repositoryItemNosaukums.DisplayMember = "Name";
    
        repositoryItemPieteikumaNr.DataSource = model;
        repositoryItemPieteikumaNr.ValueMember = "ID";
        repositoryItemPieteikumaNr.DisplayMember = "Number";