Hi Lisa,
Thanks for using Syncfusion products.
We have analyzed your scenario.
In order to have value member display member options for combo box cell types, then the ValueMember and DisplayMember of the columns must be specified. Please make use of the below code,
Code Example
private DataTable GetTheComboTable()
{
DataTable dt = new DataTable("ComboValues");
dt.Columns.Add(new DataColumn("Value", typeof(int)));
dt.Columns.Add(new DataColumn("Text",typeof(string)));
dt.Rows.Add(new object[] { 7, "1 Week" });
dt.Rows.Add(new object[] { 30, "1 Month" });
dt.Rows.Add(new object[] { 365, "1 Year" });
dt.Rows.Add(new object[] { 730, "2 Years" });
return dt;
}
comboTable = this.GetTheComboTable();
gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false;
gridGroupingControl1.TableDescriptor.Columns["ComboValues"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.ComboBox;
gridGroupingControl1.TableDescriptor.Columns["ComboValues"].Appearance.AnyRecordFieldCell.DataSource = this.comboTable;
gridGroupingControl1.TableDescriptor.Columns["ComboValues"].Appearance.AnyRecordFieldCell.DisplayMember = "Text";
gridGroupingControl1.TableDescriptor.Columns["ComboValues"].Appearance.AnyRecordFieldCell.ValueMember = "Value";
The reported scenario of displaying the display text and adding the cell values dynamically to combo box items can be achieved using the TableControlCurrentCellEditingComplete event. If the newly typed value is not in the existing combo box items, then the new item can be added to items source through ListControlPart.DataSource using the current cell renderer of the Combobox. Please make use of the below code,
Code Example
//Event subscription.
this.gridGroupingControl1.TableControlCurrentCellEditingComplete += new GridTableControlEventHandler(gridGroupingControl1_TableControlCurrentCellEditingComplete);
void gridGroupingControl1_TableControlCurrentCellEditingComplete(object sender, GridTableControlEventArgs e)
{
GridCurrentCell currentCell= e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(currentCell.RowIndex, currentCell.ColIndex);
if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "ComboValues")
{
GridDropDownGridListControlCellRenderer renderer = e.TableControl.CurrentCell.Renderer as GridDropDownGridListControlCellRenderer;
if (!renderer.ListControlPart.Items.Contains(style.CellValue))
{
int cellValue; string displayText;
if (int.TryParse(style.CellValue.ToString(), out cellValue))
{
if (cellValue % 7 == 0)
displayText = cellValue / 7 + " Week";
else if (cellValue % 30 == 0)
displayText = cellValue / 30 + " Month";
else if (cellValue % 365 == 0)
displayText = cellValue / 365 + " Year";
else
displayText = cellValue + " Days";
DataRow newRow = comboTable.NewRow();
newRow["Value"] = cellValue;
newRow["Text"] = displayText;
comboTable.Rows.Add(newRow);
renderer.ListControlPart.DataSource = comboTable;
}
}
}
}
Sample Link
Regards,
Amal Raj U.