找回密码
 立即注册

QQ登录

只需一步,快速开始

zy2164867

中级会员

13

主题

27

帖子

756

积分

中级会员

积分
756

活字格认证

zy2164867
中级会员   /  发表于:2012-5-17 13:17  /   查看:10591  /  回复:19
private void fpSpread1_EditChange(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
        {
            //货物规格根据combo.text筛选数据
         
           
            FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxType = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
            FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxType2 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
            SqlDataReader MyDR = DbHelperSQL.ExecuteReader("select * from  物流规格表 order by 货品规格", null);
            int m = Convert.ToInt32(DbHelperSQL.GetSingle("select count(规格ID) from  物流规格表 ", null).ToString());
            int n = 0;
            comboBoxType.Editable = true;
            string[] items = new string[m];
            while (MyDR.Read())
            {
                string Str = MyDR.GetString(2);
                for (int i = 1; i < 2; i++)
                {

                    Str = Str + "  " + MyDR.GetValue(2 + i).ToString();
                }
                //if (Str.CompareTo(this.fpSpread1.ActiveSheet.ActiveCell.Text) == 1 || Str.CompareTo(this.fpSpread1.ActiveSheet.ActiveCell.Text) == 0)
                if (this.fpSpread1.ActiveSheet.ActiveCell.Text.IndexOf(Str) > -1)
                {
                    items[n] = Str;
                    n = n + 1;
                }
            }
            string[] items2 = new string[n];
            items2[0] = items[n - 1];
            comboBoxType.Items = items2;
            comboBoxType2.Clear();
            comboBoxType2.Items = items2;

            this.fpSpread1.Sheets[0].Columns[4].CellType = null;
            this.fpSpread1.Sheets[0].Columns[4].CellType = comboBoxType2;
            this.fpSpread1.Sheets[0].Columns[4].AllowAutoFilter = true;
            this.fpSpread1.Sheets[0].Columns[4].AllowAutoSort = true;

            this.fpSpread1.ButtonDrawMode = FarPoint.Win.Spread.ButtonDrawModes.CurrentRow;

            AutoCompleteStringCollection acsc = new AutoCompleteStringCollection();
            acsc.AddRange(items2);

            comboBoxType2.AutoCompleteCustomSource = acsc;
            comboBoxType2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            comboBoxType2.AutoCompleteSource = AutoCompleteSource.CustomSource;
            FarPoint.Win.FpCombo cmb = fpSpread1.EditingControl as FarPoint.Win.FpCombo;
        我在fpSpread1_EditChange事件写的代码,想实现Combobox列模糊检索Combobox中的Items ,但是执行完出现未将对象引用到实例,帮我看看怎么个情况?

19 个回复

倒序浏览
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-5-17 13:58:00
沙发
请问哪一行代码运行报错呢,能否将fpSpread1_EditChange中的代码都贴上来看一看

从以上代码来看,可能出错的地方是 FarPoint.Win.FpCombo cmb = fpSpread1.EditingControl as FarPoint.Win.FpCombo;

如果你当前编辑列的CellType不是ComboBoxCellType,取到的cmb就是null,如果在后面的代码中使用cmb就会报错。
回复 使用道具 举报
zy2164867
中级会员   /  发表于:2012-5-17 14:08:00
板凳
刚才多粘代码了,没有后面那块,我修改了代码,你再看看,报错的地方不是在这个表单,是在上一个表单调用这个表单地方: frm.ShowDialog();错误指向上层表单调用这个表单的这句代码
调试的时候   this.fpSpread1.Sheets[0].Columns[4].CellType = comboBoxType2;
这句代码没有就不报错,有就报错
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-5-17 14:13:00
地板
直接看这行代码并没有什么可疑的地方,你能否做一个Demo给我,我调试一下,谢谢。
回复 使用道具 举报
zy2164867
中级会员   /  发表于:2012-5-17 14:18:00
5#
好的,怎么传给你?
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-5-17 14:23:00
6#
压缩成rar或者zip之后,通过【高级回复】【添加附件】进行上传
回复 使用道具 举报
zy2164867
中级会员   /  发表于:2012-5-17 15:05:00
7#
好的,我弄完就发给你
回复 使用道具 举报
zy2164867
中级会员   /  发表于:2012-5-17 16:55:00
8#

新做的demo,帮我调试下

作了一个,帮我调试成模糊检索Combobox中的Items DEMO.rar (297.46 KB, 下载次数: 943)
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-5-17 17:42:00
9#
zy2164867 你好

我调试了你的Demo,你Demo中要连接到数据库,而我这边没有和你一样的数据库,我就简单修改了你的代码

将动态生成Items的过程改成了直接赋值,然而,没有能够重现你的问题,附件是我修改之后的代码,你查看一下

在第4列输入A可以检索出A相关的数据

DEMO.zip (343.82 KB, 下载次数: 968)
回复 使用道具 举报
zy2164867
中级会员   /  发表于:2012-5-17 19:35:00
10#
谢谢了,我先看看,我发的压缩包里面有个“数据库bak”是数据库文件
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部