无法将DataTable绑定到ComboBoxCellType中,需要进行简单的转换,代码如下:
- private void Form1_Load(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("Col1");
- dt.Columns.Add("Col2");
- dt.Columns.Add("Col3");
- dt.Columns.Add("Col4");
- dt.Rows.Add(10, "AAA", 2, 3);
- dt.Rows.Add(20, "BBB", 2, 3);
- dt.Rows.Add(30, "CCC", 2, 3);
- dt.Rows.Add(40, "DDD", 2, 3);
- dt.Rows.Add(50, "EEE", 2, 3);
- dt.Rows.Add(60, "FFF", 2, 3);
- List<string> items = new List<string>();
- foreach (DataRow row in dt.Rows)
- {
- items.Add(row["Col2"].ToString());
- }
- FarPoint.Win.Spread.CellType.ComboBoxCellType cbo = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
- cbo.Items = items.ToArray<string>();
- fpSpread1.ButtonDrawMode = FarPoint.Win.Spread.ButtonDrawModes.CurrentCell;
- fpSpread1.ActiveSheet.DataAutoCellTypes = false;
- fpSpread1.DataSource = dt;
- fpSpread1.ActiveSheet.Columns[1].CellType = cbo;
- }
复制代码 |