I have a GridDataBoundGrid with a BindingList<T> as its data source. For a specific column, I want to be able to select an icon using a combobox. Currently, it works well. I use a GridDropDownGridListControlCellRenderer to render the dropdown with the images and their information.
The only thing that I'm missing is that when the dropdown is closed, I only see the display string and not the icon in the closed combobox. How could I have a combobox that displays the icons with the choices and with the selected choice when the combobox is closed?
My current solution is to add an uneditable column right beside the column with the combo box that would display the icon of the selected choice, but I'd like to know if there's a better way.
Here's a sample of the code I'm using:
When the form is loaded:
// We initialize the control for the color column.
GridDropDownGridListControlCellRenderer colorComboBoxRenderer = ( GridDropDownGridListControlCellRenderer ) gridDataBoundGridIndicationList.CellRenderers["GridListControl"];
// We hide the column header, the horizontal lines and the vertical lines
// in the drop down grid list control to make it look like a normal combo box.
colorComboBoxRenderer.ListControlPart.Grid.Properties.ColHeaders = false;
colorComboBoxRenderer.ListControlPart.Grid.Properties.DisplayHorzLines = false;
colorComboBoxRenderer.ListControlPart.Grid.DisplayVerticalLines = false;
// We bind the indication colors' information to the grid list control for the color selection.
gridBoundColumnColor.StyleInfo.CellType = "GridListControl";
gridBoundColumnColor.StyleInfo.DataSource = IndicationListManagerUtil.GetColorDisplayableInformations();
gridBoundColumnColor.StyleInfo.DisplayMember = "UserString";
gridBoundColumnColor.StyleInfo.ValueMember = "Color";
gridBoundColumnColor.StyleInfo.ImageList = imageListColors;
On CurrentCellShowingDropDown:
GridCurrentCell currentCell = gridDataBoundGridIndicationList.CurrentCell;
if ( currentCell.ColIndex == ColumnIndexColor && currentCell.Renderer.GetType() == typeof( GridDropDownGridListControlCellRenderer ) )
{
GridDropDownGridListControlCellRenderer renderer = ( GridDropDownGridListControlCellRenderer ) currentCell.Renderer;
// We set the width to the icon's width so the IndicationColor.ToString() doesn't show up.
renderer.ListControlPart.Grid.ColWidths[1] = 16;
}
On CurrentCellCloseDropDown:
GridCurrentCell currentCell = gridDataBoundGridIndicationList.CurrentCell;
if ( currentCell.Renderer is GridDropDownGridListControlCellRenderer )
{
GridDropDownGridListControlCellRenderer renderer = ( GridDropDownGridListControlCellRenderer ) currentCell.Renderer;
renderer.ListControlPart.Grid.Properties.ColHeaders = false;
if ( e.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done && renderer.ToString() == "GridDropDownGridListControlCellRenderer" )
{
// Set the image to the current cell.
gridDataBoundGridIndicationList[currentCell.RowIndex, currentCell.ColIndex].ImageIndex = renderer.ListControlPart.SelectedIndex;
}
}