Spread Studio for .NET:ComboxCellType 不同选项定制不同的背景色

发布时间:2014/03/04 00:03 发布者:iceman

返回博客中心

本文描述如何通过获取 ComboxCellType 单元格类型的选择事件进而更改当前单元格的背景色。有用户提出希望通过Combo的选择项不同更改不同的背景色,突出选择效果。

代码如下:

添加ComboCellType 单元格类型

/// <summary>
        /// 添加 ComboBoxCellType 单元格类型
        /// </summary>
        private void AddCellType()
        {
            FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxCellType1 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
            comboBoxCellType1.Items = (new String[] { "红色", "绿色", });
            fpSpread1.Sheets[0].Cells[0, 0].CellType = comboBoxCellType1;
            comboBoxCellType1.EditorValueChanged += new EventHandler(comboBoxCellType1_EditorValueChanged);
        }
 

 

通过事件判断选择文本更改背景色:

void comboBoxCellType1_EditorValueChanged(object sender, EventArgs e)
        {
            FarPoint.Win.Spread.CellType.ComboBoxCellType test = sender as FarPoint.Win.Spread.CellType.ComboBoxCellType;
            if (this.fpSpread1.Sheets[0].ActiveCell.Text == "ᄎ↓￉ᆱ")
            {
                this.fpSpread1.Sheets[0].ActiveCell.BackColor = Color.Red;
            }
            if (this.fpSpread1.Sheets[0].ActiveCell.Text == "ᅡᅩ￉ᆱ")
            {
                this.fpSpread1.Sheets[0].ActiveCell.BackColor = Color.Green;

            }
        }

效果截图:

Demo下载:

spread_win_comboselect.zip (43.66 kb)


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网