找回密码
 立即注册

QQ登录

只需一步,快速开始

xiafu568

初级会员

41

主题

84

帖子

291

积分

初级会员

积分
291

活字格认证微信认证勋章

xiafu568
初级会员   /  发表于:2013-5-29 11:35  /   查看:4171  /  回复:1
现有两列combobox下拉列表,现在想通过前一列所选的值,来判断第二列下拉列表应该有什么选项
比如说,前一列选1,第二列下拉列表可供选择的有1,2,3
前一列选2,第二列下拉列表可供选择的有4,5,6

1 个回复

倒序浏览
Ally
葡萄城公司职员   /  发表于:2013-5-29 14:28:00
沙发
您好!
您可以运行以下代码实现您的需求:
ComboBoxCellType combo2 = new ComboBoxCellType();
        public Form1()
        {
            InitializeComponent();
            fpSpread1.EditModeOn += fpSpread1_EditModeOn;
            ComboBoxCellType combo1 = new ComboBoxCellType();
            combo1.Items = new string[] { "Item1", "Item2", "Item3", "Item4" };
            combo1.EditorValue = EditorValue.Index;
            fpSpread1.ActiveSheet.Cells[1, 1].CellType = combo1;            
            fpSpread1.ActiveSheet.Cells[2, 2].CellType = combo2;
        }
        void fpSpread1_EditModeOn(object sender, EventArgs e)
        {
            if (fpSpread1.ActiveSheet.ActiveCell.Row.Index == 1 && fpSpread1.ActiveSheet.ActiveCell.Column.Index == 1)
            {
                (fpSpread1.EditingControl as FpCombo).SelectedIndexChanged += Form1_SelectedIndexChanged;            
            }
        }
        void Form1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if((sender as FpCombo).SelectedIndex == 0)
            {
                combo2.Items = new string[] { "Item1", "Item2", "Item3" };
            }
            if ((sender as FpCombo).SelectedIndex == 1)
            {
                combo2.Items = new string[] { "Item4", "Item5", "Item6" };
            }
        }
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部