Spread Windows Forms 11.0 Product Documentation
Setting a Combo Box Cell
Spread Windows Forms 11.0 Product Documentation > Developer's Guide > Customizing Interaction with Cell Types > Working with Graphical Cell Types > Setting a Combo Box Cell

You can use a combo box cell to display an editable drop-down list, allowing the user to type in values as well as choosing from a displayed list. You can specify the list of items, whether to include icons to appear along with text, the number of items that are displayed at any time, and whether the cell is editable by the user.

Text only Text and icon

Combo box with four text choices showing and vertical scroll bar

Combo box with icons along with text

To create a cell that acts like a combo box, use the ComboBoxCellType class. Create a combo box cell using the following procedure.

Customizing the List Appearance

Use the following appearance properties to customize the combo box.

Property Description
BackgroundImage Sets an image to paint in the background of the edit portion of the combo box.
ButtonAlign Sets where buttons are displayed.
ImageList Sets an image list for displaying icons along with text in the drop-down list in the combo box.
ItemData Sets item data, which is different from the items that are displayed, for the drop-down list in the combo box.
Items Sets items for the drop-down list in the combo box.
ListAlignment Sets the side of the cell on which the list aligns.
ListOffset Sets how many pixels to offset the list from the aligned edge of the cell.
ListWidth Sets the width (in pixels) of the drop-down list.
MaxDrop Sets the number of items to display at one time in the list portion. If there are more items than are displayed, a vertical scroll bar is displayed.
MaxLength Sets the maximum number of characters allowed in the combo box cell.

Customizing the List Operation

Use the following operation properties to customize the combo box.

Property Description
AcceptsArrowKeys Sets how arrow keys are processed by the combo box control.
AutoSearch Sets how a list of items in a combo box is searched based on input of a character key.
CharacterCasing Sets the case of characters in the text cell.
CharacterSet Sets what characters to allow for the text cell.
Editable Sets whether you can type into the edit portion of the combo box.
EditorValue Sets what value is written to the underlying data model.
ListControl Sets the control to use for the list portion if you do not want to use the built-in list control in Spread.

The Spread control has a ButtonDrawMode property for button cells and combo box cells. This property allows you to always show a button, or show buttons in the current column, row, or cell.

Customizing Automatic Completion

Use the following properties to customize the automatic completion feature in combo box cells when using the 2005 build of the component.

Property Description
AutoCompleteCustomSource Set the custom source (strings) for automatic completion of entries in the combo box.
AutoCompleteMode Set the mode for automatic completion of entries in the combo box.
AutoCompleteSource Set the source for automatic completion of entries in the combo box.

Note that some graphical elements in certain cell types are affected by XP themes (visual styles). Setting the VisualStyles property of the Spread component to "off" can allow visual customizations of those graphical cell types to work as expected. For more information, refer to Using XP Themes with the Component.

To display a text tip over a combo box cell, see the note in Displaying Text Tips in a Cell.

For more information on the properties and methods of this cell type, refer to the ComboBoxCellType class. For information on the multiple-column combo box, refer to Setting a Multiple-Column Combo Box Cell.

Using the Properties Window

  1. At design time, in the Properties window, select the Spread component.
  2. Select the Sheets property.
  3. Click the button to display the SheetView Collection Editor.
  4. In the Members list, select the sheet in which the cells appear.
  5. In the property list, select the Cells property and then click the button to display the Cell, Column, and Row Editor.
  6. Select the cells for which you want to set the cell type.
  7. In the property list, select the CellType property and choose the ComboBox cell type.
  8. Expand the list of properties under the CellType property. Select and set these specific properties as needed.
  9. Click OK to close the Cell, Column, and Row Editor.
  10. Click OK to close the SheetView Collection Editor.

Using Code

  1. Define a combo box cell by creating an instance of the ComboBoxCellType class.
  2. Specify the items in the list that appear as part of the combo box. You can either use the Items property of the ComboBoxCellType class or define a string and pass that in when creating the instance of the class.
  3. Specify how the list of items appears. For example, set the MaxDrop property to set the maximum number of items to display at a time. If there are more items, a scroll bar appears. You can also set the horizontal alignment of the check box with respect to the cell.
  4. Assign the combo box cell type to a cell or range of cells by setting the CellType property for a cell, column, row, or style to the ComboBoxCellType object.

Example

This example creates a combo cell.

C#
Copy Code
FarPoint.Win.Spread.CellType.ComboBoxCellType cmbocell = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
cmbocell.Items = (new String[] {"January", "February", "March", "April", "May", "June"});
cmbocell.AutoSearch = FarPoint.Win.AutoSearch.SingleCharacter;
cmbocell.Editable = true;
cmbocell.MaxDrop = 4;
fpSpread1.ActiveSheet.Cells[0, 0].CellType = cmbocell;
VB
Copy Code
Dim cbstr As string( )
cbstr = New String() {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}
Dim cmbocell As New FarPoint.Win.Spread.CellType.ComboBoxCellType()
cmbocell.Items = cbstr
cmbocell.AutoSearch = FarPoint.Win.AutoSearch.SingleCharacter
cmbocell.Editable = True
cmbocell.MaxDrop = 4
fpSpread1.ActiveSheet.Cells(0, 0).CellType = cmbocell

Using the Spread Designer

  1. Select the cell or cells in the work area.
  2. In the property list, in the Misc category, select CellType. From the drop-down list, choose the ComboBox cell type. Now expand the CellType property and various properties are available that are specific to this cell type. Select and set those properties as needed.

    Or right-click on the cell or cells and select Cell Type. From the list, select ComboBox. In the CellType editor, set the properties you need. Click Apply.

  3. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
See Also