Spread ASP.NET 18
Spread for ASP.NET 18 Product Documentation / Developer's Guide / Customizing with Cell Types / Working with Graphical Cell Types / Setting a Combo Box Cell
In This Topic
    Setting a Combo Box Cell
    In This Topic

    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 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.

    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[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 
    

    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();
    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 
    

    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.
    See Also