We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GridDataBoundGrid ComboBox List Binding

I am binding the combobox lists for an entire column as follows: this.GridBoundColumns[iColIndex].StyleInfo.DataSource = oListTable; this.GridBoundColumns[iColIndex].StyleInfo.DisplayMember = "DisplayColumn"; this.GridBoundColumns[iColIndex].StyleInfo.ValueMember = "ValueColumn"; This works fine. Then, depending on user input, I need to rebind the combobox list of a single cell and am trying to use this code: GridStyleInfo oCurrCell = this[iRowIndex, iColIndex]; if (null != oCurrCell) { oCurrCell.DataSource = oListTable; oCurrCell.DisplayMember = "DisplayColumn"; oCurrCell.ValueMember = "ValueColumn"; } This doesn't have any affect. What do I need to do to change the data binding of the combobox list for the current cell?

1 Reply

AD Administrator Syncfusion Team January 27, 2003 09:06 PM UTC

In a GridDataBoundGrid, there is no grid data object to store individual cell properties. So, you cannot use code like grid[row, col].DataSource = xyz. The reason is that there is no place to store this individual cell data. (The only thing you can do by indexing a grid cell is to set the Text or CellValue property as this property is mapped back to the DataSource bound to the GridDataBoundGrid.) To change individual cell style attributes, you can use either the GridDataBoundGrid.PrepareViewStyleInfo event, or the GridDataBoundGrid.Model.QueryCellInfo event. The PrepareViewStyleInfo is generally used for style propeties that affect the appearance of the cell (such as the BackColor or Font). QueryCellInfo is used to handle properties that may be used by other aspects of the grid. To change the DataSource, DisplayMember and ValueMember, I would first try QueryCellInfo. Here is some code that sets the displaymember in col 4 based on the cell value in col 2.
private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
	if(e.RowIndex > 0 && e.ColIndex == 4)
		e.Style.CellType = "ComboBox";
		e.Style.DataSource = this.foreignKeys;
		e.Style.DisplayMember = this.gridDataBoundGrid1[e.RowIndex, 2].Text;
		e.Style.ValueMember = "WordID";
		e.Handled = true;

Live Chat Icon For mobile
Up arrow icon