Xceed Grid for WinForms v4.3 Documentation
ComboBoxViewer

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > CellEditorManagers and CellViewerManagers > How to use cell viewers > ComboBoxViewer

The ComboBoxViewer can be used to view the content of cells which have an ID/Value mapping.

Using the ComboBoxViewer

The ComboBoxViewer is never used as a default CellViewerManager unless specified otherwise by either setting the CellViewerManager property of a specific column or cell, or by mapping it to a datatype via the GridControl's CellViewerManagerMapping property. 

In order to use the ComboBoxViewer, it must be bound to a datasource. Normally, it is used to display the text equivalent of an ID. For example, if a grid contains a "ProductID " column and the description of the product is in the "Products" table under the " ProductName" column, the ComboBoxViewer can be used to display the name of the product rather than its ID. 

To bind the ComboBoxViewer to a datasource, the DataSource and DataMember properties must be set (or the SetDataBinding method called), the "ID" column specified through the ValueMember property, and the "Value/Name" column specified through the DisplayFormat property. Contrary to the regular Windows Forms combobox which exposes a DisplayMember property, the ComboBoxViewer uses the DisplayFormat property which can display values from more than one column (from the corresponding ComboBoxEditor).

VB.NET
Copy Code
Dim viewer As New ComboBoxViewer( northwindDataSet, "Products", "ProductID", "%ProductName%" )
GridControl1.Columns( "ProductID" ).CellViewerManager = viewer
C#
Copy Code
ComboBoxViewer viewer = new ComboBoxViewer( northwindDataSet, "Products", "ProductID", "%ProductName%" );
gridControl1.Columns[ "ProductID" ].CellViewerManager = viewer;
The DisplayFormat property determines the format with which the selected item is displayed. By default, if no display format is specified, the values of each column in the selected item—separated by a comma (,)—will be displayed. For more information on the DisplayFormat property, refer to the Display format topic. 

The text displayed by the ComboBoxViewer can be retrieved via the GetText method. 

As of version 3.1, images can also be displayed in the ComboBoxViewer. By default, the ImageArea property is set to ImageArea.None indicating that no image is displayed. In order to display an image, the ImageArea property must be set to either Left, Right, or AllContent. Once the ImageArea property has been set, an image can be specified by setting the ImageMember property to the field in the datasource from which to retrieve the appropriate image, by overriding the GetImageCore method, or by handling the QueryImage event. The image displayed in the ComboBoxViewer can be retrieved via the GetImage method. 

The size, style, padding, and alignment of the image can be modified through the ImageSize, ImageStyle, ImagePadding, and ImageAlignment properties respectively.

VB.NET
Copy Code
Dim viewer As New ComboBoxViewer( dataSet11, "Employees", "EmployeeID", "Photo", ImageArea.Left,
New Size( 32, 32 ), "%FirstName% %LastName%" )
GridControl1.Columns( "EmployeeID" ).CellViewerManager = viewer
GridControl1.Columns( "EmployeeID" ).Title = "Employee"
C#
Copy Code
ComboBoxViewer viewer = new ComboBoxViewer( dataSet11, "Employees", "EmployeeID", "Photo", ImageArea.Left,
new Size( 32, 32 ), "%FirstName% %LastName%" );
gridControl1.Columns[ "EmployeeID" ].CellViewerManager = viewer;
gridControl1.Columns[ "EmployeeID" ].Title = "Employee";

Underlying control

The underlying control wrapped by the ComboBoxViewer is the WinComboBox control and is accessible through the Control property. All settings relating to the underlying control must be accessed via the Control property. 

More information regarding the WinComboBox control can be found in the WinComboBox control topic.

Limitations

The current version of the ComboBoxViewer does not directly support unbound mode. As a work-around, if there is a ComboBoxEditor counterpart, the TemplateControl of the ComboBoxEditor can be cloned, and wrapped in a CellViewerManager.

VB.NET
Copy Code
Dim comboEditor As New ComboBoxEditor()
comboEditor.Items.Add( "Received" )
comboEditor.Items.Add( "Pending" )
comboEditor.Items.Add( "Out Of Stock" )
      
Dim control As WinComboBox = CType( comboEditor.TemplateControl.Clone(), WinComboBox )
control.SideButtons.Remove( control.DropDownButton )
Dim unboundViewer As New CellViewerManager( control, string.Empty )
gridControl1.Columns( "State" ).CellEditorManager = comboEditor
gridControl1.Columns( "State" ).CellViewerManager = unboundViewer
C#
Copy Code
ComboBoxEditor comboEditor = new ComboBoxEditor();
comboEditor.Items.Add( "Received" );
comboEditor.Items.Add( "Pending" );
comboEditor.Items.Add( "Out Of Stock" );
      
WinComboBox control = ( WinComboBox )comboEditor.TemplateControl.Clone();
control.SideButtons.Remove( control.DropDownButton );
CellViewerManager unboundViewer = new CellViewerManager( control, string.Empty );
gridControl1.Columns[ "State" ].CellEditorManager = comboEditor;
gridControl1.Columns[ "State" ].CellViewerManager = unboundViewer;