将ComboBox的数据源设置为DataSet的方法请参考以下代码:
- protected void Page_Load(object sender, EventArgs e)
- {
- DataSet ds = new System.Data.DataSet();
- DataTable name,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("CityCode", 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 cb = new FarPoint.Web.Spread.ComboBoxCellType();
- cb.DataSource = ds;
- cb.ShowButton = false;
- cb.DataMember = "City/State";
- cb.DataTextField = "city";
- cb.DataValueField = "CityCode";
- cb.UseValue = true;
- //通过CellType设置ComboBox
- FpSpread1.ActiveSheetView.Columns[0].CellType = cb;
- //通过Editor设置ComboBox
- FpSpread1.ActiveSheetView.Columns[2].Editor = cb;
- }
复制代码 |