this.sfDataGrid.CellRenderers.Add("DropDownDataGrid", new GridDropDownDataGridCellRenderer(this.sfDataGrid));
sfDataGrid.Columns.Add(new GridDropDownDataGridColumn() { MappingName = "ShipCityID", HeaderText = "Ship City", DataSource = new CountryInfoRepository().Cities });
public class GridDropDownDataGridColumn : GridColumn
{
public GridDropDownDataGridColumn()
{
SetCellType("DropDownDataGrid");
}
public IEnumerable DataSource { get; set; }
}
public class GridDropDownDataGridCellRenderer : GridVirtualizingCellRendererBase<ComboDropDown>
{
SfDataGrid DataGrid { get; set; }
public GridDropDownDataGridCellRenderer(SfDataGrid dataGrid)
{
DataGrid = dataGrid;
}
protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
{
base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex);
}
protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, ComboDropDown uiElement)
{
Rectangle editorRectangle = GetEditorUIElementBounds();
uiElement.Size = editorRectangle.Size;
uiElement.Location = editorRectangle.Location;
uiElement.DropDownWidth = 300;
SfDataGrid dropDownDataGrid = new SfDataGrid()
{
DataSource = (column.GridColumn as GridDropDownDataGridColumn).DataSource,
};
uiElement.PopupControl = dropDownDataGrid;
this.TableControl.Controls.Add(uiElement);
uiElement.Focus();
base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
}
} |