hi,
i would like to know how to add a combo box in the datagrid(GridControl and GDBC)?
And when the value of the combobox is changed, it will caused the value of another column is changed also.
Thanks.
AD
Administrator
Syncfusion Team
January 10, 2007 09:17 AM UTC
Hi Lim,
Try this code.
StringCollection sc = new StringCollection();
sc.Add("One");
sc.Add("Two");
sc.Add("Three");
sc.Add("Four");
this.grid.Model.ColStyles[1].CellType = "ComboBox";
this.grid.Model.ColStyles[1].ChoiceList = sc;
Also refer our ComboBoxCells browser sample which illustrates how you can use ComboBoxes and Dropdown Multicolumn GridListControls in grid cells.
[install path]\Syncfusion\Essential Studio\4.4.0.49\windows\Grid.Windows\Samples\CellTypes\ComboboxCells\cs
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
January 10, 2007 10:38 AM UTC
hi haneef,
What should i do in order to fulfill the requirement as below:
When the value of the combobox is changed, the value of the rest of the columns are changed based on the combobox's value.
Thanks!
AD
Administrator
Syncfusion Team
January 10, 2007 11:45 AM UTC
Hi Lim,
You can subscribe the CurrentCellChanged event of the grid and change the value of the rest of the column cells using the Renderer.ControlValue(it holds the newly changed value) through Model property of the grid. Here is a code snippet.
void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = grid.CurrentCell;
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
if (cr != null)
{
object EditState = cr.GetEditState();
for (int i = 1; i < grid.Model.RowCount; i++)
grid.Model[i, cc.ColIndex].CellValue = cr.ControlValue;
cr.SetEditState(EditState);
}
}
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
January 16, 2007 07:42 AM UTC
hi haneef,
It's working!
Another problem is how to do validating on the user input in the combo box? If the input is not one of the item of the combo box's datasource, the user input is should be cancelled and rollback to the previous input..
Thanks
AD
Administrator
Syncfusion Team
January 16, 2007 08:46 PM UTC
Hi Lim,
Before changing the value of the rest of the column cells, you need to check the Renderer.ControlValue with the underlying datasource of the cell. Please refer the following code snippet.
void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e){
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = grid.CurrentCell;
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
if (cr != null){
object EditState = cr.GetEditState();
for (int i = 1; i < grid.Model.RowCount; i++)
{
if( CheckValue(cr.ControlValue,grid.Model[i, cc.ColIndex].ChoiceList))
grid.Model[i, cc.ColIndex].CellValue = cr.ControlValue;
}
cr.SetEditState(EditState);
}
}
private bool CheckValue(object svalue,StringCollection sc){
return svalue != null && sc != null && sc.Contains(svalue.ToString());
}
Best Regards,
Haneef