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

Image ComboBox in a cell

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;

        }

      }



1 Reply

AS Asarudheen S Syncfusion Team May 11, 2012 08:58 AM UTC

Hi Adam,

Thanks for being patient.

Please make use of the method “currentcell.EndEdit()” to resolve the reported issue “when the dropdown is closed, the icon is not displayed in the closed combobox” and refer the following code.

void gridDataBoundGrid_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e)

        {

            GridCurrentCell currentcell = this.gridControl1.CurrentCell;

              GridDropDownGridListControlCellRenderer renderer = ( GridDropDownGridListControlCellRenderer ) currentcell.Renderer;

         

            if (e.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done)

            {

                this.gridDataBoundGrid[currentcell.RowIndex, currentcell.ColIndex].ImageIndex = renderer.ListControlPart.SelectedIndex;

               currentcell.EndEdit();

            }

        }

Please let us know if this helps.

Regards,

Asarudheen.


Loader.
Live Chat Icon For mobile
Up arrow icon