Why to lose my choice list when I try to use both the choice lists and DataSources to populate the ComboBoxes in different cells in WinForms GridControl?
Choice list with a combobox cell by using a datasource
Normally, Essential Grid uses the same combobox for all the cells with the celltype ComboBox in the Grid. When you move from one combobox cell to another, the choicelist (or DataSource, depending upon what you are using) is swapped out to reflect the settings of a new cell. When you try to swap the combobox cell by using a choicelist with a combobox cell by using a DataSource, it does not work.
Solution
To overcome this, create two ComboBox cell models, one for choicelists and another for DataSources. You can use the GridControl.CellModels.Add a method to add this second cell type.
//Adds a new ComboBox CellModel
this.gridControl1.CellModels.Add("ComboBoxDS", new GridComboBoxCellModel(this.gridControl1.Model));'Adds a new ComboBox CellModel
Me.gridControl1.CellModels.Add("ComboBoxDS", New GridComboBoxCellModel(Me.gridControl1.Model))This registers a new cell type named ComboBoxDS that is just another ComboBox cell. You can use the ComboBoxDS as the cell type for your cells that require a DataSource, and use the ComboBox as the cell type for the cells that require a ChoiceList.
Adding the ChoiceList/DataSource to the ComboBox cell:
//Sets the CellType to ComboBox
this.gridControl1[2, 2].CellType = "ComboBox";
this.gridControl1[2, 3].CellType = "ComboBoxDS";
//Adds the CellValue to the Cells
this.gridControl1[2, 2].CellValue = "one";
this.gridControl1[2, 3].CellValue = "one";
//Adds the ChoiceList to the ComboBox cell
this.gridControl1[2, 2].ChoiceList =list;
//Adds the DataSource to the ComboBox cell
this.gridControl1[2, 3].DataSource = list;'Sets the CellType to ComboBox
Me.gridControl1(2, 2).CellType = "ComboBox"
Me.gridControl1(2, 3).CellType = "ComboBoxDS"
'Adds the CellValue to the Cells
Me.gridControl1(2, 2).CellValue = "one"
Me.gridControl1(2, 3).CellValue = "one"
'Adds the ChoiceList to the ComboBox cell
Me.gridControl1(2, 2).ChoiceList =list
'Adds the DataSource to the ComboBox cell
Me.gridControl1(2, 3).DataSource = list Note:
This problem has been resolved in our later versions of Essential Studio Grids.
Samples: