请先使用下面的代码进行测试,主要是设置Columns[0].Editor和Renderer属性为不同类型:
- namespace _5164_ComboBox
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- FarPoint.Win.Spread.CellType.ComboBoxCellType combo = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
- string[] cbstr;
- cbstr = new String[] { "是", "否" };
- string[] strval;
- strval = new String[] { "1", "2" };
- combo.Items = cbstr;
- combo.ItemData = strval;
- combo.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData;
- fpSpread1.Sheets[0].Columns[0].Editor = combo;
- fpSpread1.Sheets[0].Columns[0].Renderer = new MyCellType();
- fpSpread1.ActiveSheet.Cells[0, 0].Value = 1;
- fpSpread1.ActiveSheet.Cells[1, 0].Value = 2;
- fpSpread1.ActiveSheet.Cells[2, 0].Value = 1;
- fpSpread1.ActiveSheet.Cells[3, 0].Value = 2;
- }
- }
- public class MyCellType : FarPoint.Win.Spread.CellType.GeneralCellType
- {
- public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
- {
- if (value != null)
- {
- if (value.ToString() == "1")
- {
- value = "是";
- }
- else if(value.ToString() == "2")
- {
- value = "否";
- }
- }
- base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
- }
- }
- }
复制代码 |