Spread ASP.NET 6.0 Product Documentation
Setting a Combo Box Cell
Send Feedback
Spread ASP.NET 6.0 Product Documentation > Developer's Guide > Customizing with Cell Types > Working with Graphical Cell Types > Setting a Combo Box Cell

Glossary Item Box

A combo box cell displays an editable type box with a drop‑down list of items when the cell is selected. The user may either type in the editable box (which searches for the item in the list) or select an item from the drop‑down list. You can customize the appearance of the drop‑down list as well as its behavior.

Combo Box Cell Type with Combo Box Open

The combo box cell can be bound to data by setting DataSource, DataSourceID, DataMember, DataTextField, or DataValueField.

To create a cell that acts like a combo box, follow the procedure described here.

For details on the properties and methods for this cell type, refer to the ComboBoxCellType class in the Assembly Reference.

Return to the overview of graphical cell types at Working with Graphical Cell Types.

Using Code

  1. Define a combo box cell type by creating an instance of the ComboBoxCellType class.
  2. Specify the items in the list that appear as part of the combo box.
  3. Assign the list of items to a cell (or cells) defined as a combo box cell(s).
  4. Specify any properties for that cell (or cells).
  5. Assign the combo box cell type to a cell (or cells).

Example

This example creates a string array and adds the items to the combo cell.

C# Copy Code
string[] cbstr;
cbstr = new String[] {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; 
FarPoint.Web.Spread.ComboBoxCellType cmbbx = new FarPoint.Web.Spread.ComboBoxCellType(cbstr); 
FpSpread1.ActiveSheetView.Cells[0, 0].CellType = cmbbx;
VB Copy Code
Dim cbstr As string( )
cbstr = new String() {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}
Dim cmbbx As New FarPoint.Web.Spread.ComboBoxCellType(cbstr)
FpSpread1.ActiveSheetView.Cells(0, 0).CellType = cmbbx

Using Code

  1. Define a combo box cell type by creating an instance of the ComboBoxCellType class.
  2. Specify the data base table that is the source of the combo box drop-down list.
  3. Populate a combo box drop-down list with values from a database table.
  4. Specify any properties for that cell (or cells).
  5. Assign the combo box cell type to a cell (or cells).

Example

This example creates a dataset and adds the items to the combo cell.

C# Copy Code
System.Data.DataSet ds = new System.Data.DataSet(); 
DataTable name; 
DataTable city; 
name = ds.Tables.Add("Customers"); 
name.Columns.AddRange(new DataColumn[] {new DataColumn("LastName", typeof(string)), new DataColumn("FirstName", typeof(string)), 
new DataColumn("ID", typeof(Int32))}); 
name.Rows.Add(new object[] {"Fielding", "William", 0}); 
name.Rows.Add(new object[] {"Williams", "Arthur", 1}); 
name.Rows.Add(new object[] {"Zuchini", "Theodore", 2}); 
city = ds.Tables.Add("City/State"); 
city.Columns.AddRange(new DataColumn[] {new DataColumn("City", typeof(string)), new DataColumn("Owner", typeof(Int32)), new DataColumn("State", typeof(string))}); 
city.Rows.Add(new object[] {"Atlanta", 0, "Georgia"}); 
city.Rows.Add(new object[] {"Boston", 1, "Mass."}); 
city.Rows.Add(new object[] {"Tampa", 2, "Fla."}); 
FarPoint.Web.Spread.ComboBoxCellType c = new FarPoint.Web.Spread.ComboBoxCellType();DataTable dt;
ArrayList al = new ArrayList(ds.Tables(0).Rows.Count); 
dt = ds.Tables(0); for (int i = 0; i<(dt.Rows.Count - 1); i++) 
{
      al.Add(dt.Rows(i)(0));}string[] s;s = al.ToArray(GetType(String)); c.Items = s;
VB Copy Code
Dim ds As New System.Data.DataSet
Dim name As DataTable
Dim city As DataTable
name = ds.Tables.Add("Customers")
name.Columns.AddRange(New DataColumn() {New DataColumn("LastName", Type.GetType("System.String")), New DataColumn("FirstName", Type.GetType("System.String")), New DataColumn("ID", Type.GetType("System.Int32"))})
name.Rows.Add(New Object() {"Fielding", "William", 0})
name.Rows.Add(New Object() {"Williams", "Arthur", 1})
name.Rows.Add(New Object() {"Zuchini", "Theodore", 2})
city = ds.Tables.Add("City/State")
city.Columns.AddRange(New DataColumn() {New DataColumn("City", Type.GetType("System.String")), New DataColumn("Owner", Type.GetType("System.Int32")), New DataColumn("State", Type.GetType("System.String"))})
city.Rows.Add(New Object() {"Atlanta", 0, "Georgia"})
city.Rows.Add(New Object() {"Boston", 1, "Mass."})
city.Rows.Add(New Object() {"Tampa", 2, "Fla."})
Dim c As New FarPoint.Web.Spread.ComboBoxCellType 
Dim dt As DataTable 
Dim al As New ArrayList(ds.Tables(0).Rows.Count) 
dt = ds.Tables(0) 
Dim i As Int32 
For i = 0 To dt.Rows.Count - 1 
al.Add(dt.Rows(i)(0)) 
Next 
Dim s As String() 
s = al.ToArray(GetType(String)) 
c.Items = s 

Using the Spread Designer

  1. In the work area, select the cell or cells for which you want to set the cell type.
  2. Select the Home menu.
  3. Select the SetCellType icon under the CellType section.
  4. Select the cell type and any other cell properties.
  5. Select OK to close the dialog.
  6. Click Apply and Exit to close the Spread Designer.
© 2002-2012 GrapeCity, Inc. All Rights Reserved.