Spread for ASP.NET 8.0 Product Documentation > Developer's Guide > Customizing with Cell Types > Working with Graphical Cell Types > Setting a Combo Box Cell |
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.
The combo box cell can be bound to data by setting the DataSource, DataSourceID, DataMember, DataTextField, or DataValueField property.
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.
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[1, 1].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(1, 1).CellType = cmbbx |
This example creates a dataset and adds the items to the combo cell.
C# |
Copy Code
|
---|---|
System.Data.DataSet ds = new System.Data.DataSet(); System.Data.DataTable name; System.Data.DataTable city; name = ds.Tables.Add("Customers"); name.Columns.AddRange(new System.Data.DataColumn[] {new System.Data.DataColumn("LastName", typeof(string)), new System.Data.DataColumn("FirstName", typeof(string)), new System.Data.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 System.Data.DataColumn[] {new System.Data.DataColumn("City", typeof(string)), new System.Data.DataColumn("Owner", typeof(Int32)), new System.Data.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(); System.Data.DataTable dt; System.Collections.ArrayList al = new System.Collections.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 = null; s = (string[])al.ToArray(typeof(string)); c.Items = s; c.ShowButton = true; FpSpread1.Sheets[0].Cells[1,1].CellType = c; |
VB |
Copy Code
|
---|---|
Dim ds As New System.Data.DataSet Dim name As System.Data.DataTable Dim city As System.Data.DataTable name = ds.Tables.Add("Customers") name.Columns.AddRange(New System.Data.DataColumn() {New System.Data.DataColumn("LastName", Type.GetType("System.String")), New System.Data.DataColumn("FirstName", Type.GetType("System.String")), New System.Data.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 System.Data.DataColumn() {New System.Data.DataColumn("City", Type.GetType("System.String")), New System.Data.DataColumn("Owner", Type.GetType("System.Int32")), New System.Data.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 System.Data.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 c.ShowButton = True FpSpread1.Sheets(0).Cells(1, 1).CellType = c |