回复 13楼holly.huang的帖子
这次理解了。
Spread ComboBoxCellType 提供了序列化和反序列化方法,具体做法如下:
- FarPoint.Win.Spread.CellType.ComboBoxCellType combo = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
- string[] cbstr;
- cbstr = new String[] { "One", "Two", "Three" };
- string[] strval;
- strval = new String[] { "1", "2", "3" };
- combo.Items = cbstr;
- combo.ItemData = strval;
- combo.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData;
- fpSpread1.Sheets[0].Cells[0, 0].CellType = combo;
- System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter("combo.xml", System.Text.Encoding.UTF8);
- writer.Formatting = System.Xml.Formatting.Indented; writer.Indentation = 2;
- writer.WriteStartDocument();
- writer.WriteStartElement("ComboBox");
- combo.Serialize(writer);
- combo.Serialize(writer);
- writer.WriteEndElement();
- writer.WriteEndDocument();
- writer.Close();
- FarPoint.Win.Spread.CellType.ComboBoxCellType combo1 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
- System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
- doc.Load("combo.xml");
- System.Xml.XmlNode node;
- node = doc.FirstChild;
- while (!node.Name.Equals("ComboBox"))
- node = node.NextSibling;
- System.Xml.XmlNodeReader r = new System.Xml.XmlNodeReader(node);
- r.Read();
- combo1.Deserialize(r);
- fpSpread1.Sheets[0].Cells[0, 1].CellType = combo1;
复制代码
所以建议您在存储数据库的同时把 ComboCellType 序列化,从数据库中提取数据绑定到 Spread 之后,再反序列化ComboCellType 设置给Combo列,这样即可自动转换了,测试代码:
- private void gettextToolStripMenuItem_Click(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("combotest",typeof(System.Int32));
- dt.Rows.Add(1);
- dt.Rows.Add(2);
- dt.Rows.Add(3);
- this.fpSpread1.DataSource = dt;
- FarPoint.Win.Spread.CellType.ComboBoxCellType combo1 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
- System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
- doc.Load("combo.xml");
- System.Xml.XmlNode node;
- node = doc.FirstChild;
- while (!node.Name.Equals("ComboBox"))
- node = node.NextSibling;
- System.Xml.XmlNodeReader r = new System.Xml.XmlNodeReader(node);
- r.Read();
- combo1.Deserialize(r);
- fpSpread1.Sheets[0].Columns[0].CellType = combo1;
-
- }
复制代码
不知道我表达的清楚吗? |