怎么防止下拉列表控件的EditvalueChanged事件进入死循环

本篇内容主要讲解“怎么防止下拉列表控件的EditvalueChanged事件进入死循环”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么防止下拉列表控件的EditvalueChanged事件进入死循环”吧!

创新互联专注为客户提供全方位的互联网综合服务,包含不限于网站设计制作、成都网站制作、林口网络推广、微信小程序开发、林口网络营销、林口企业策划、林口品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供林口建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

当 下拉列表控件选中后判定另一个为空,return之前需要将该下拉列表清空,就又会触发Changed事件,解决方案就是将空值的判断放置最外层,代码如下:

 private void gluCOATemplate_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                if (gluCOATemplate.Text != "")
                {
                    string sCoaId = gluCOATemplate.Text;
                    string sBacthId = txtLotID.Text;
                    if (txtLotID.Text == "")
                    {
                        CommonFunction.ShowMsgBox("检查批号不能为空");
                        InitgdvCoaItem();
                        gluCOATemplate.Text = "";
                        txtLotID.Focus();
                        return;
                    }
                    if (gluCOATemplate.Text == "")
                    {
                        CommonFunction.ShowMsgBox("请选择模板ID");
                        gluCOATemplate.Focus();
                        return;
                    }

                    if (txtLotID.Text != "" && sCoaId != "")
                    {
                        DataTable dt = new DataTable();
                        dt = QCMLIST.QCM_View_COA_Detail(sCoaId, sBacthId);

                        if (dt != null)
                        {
                            udcGVNewDelCtrl1.RecordCount = dt.Rows.Count;
                            //DevGridControlHelper.BindData(gdcCOAItem, dt);
                            DevGridControlHelper.BindData(gdcCOAItem, dt, new int[] { 1, 1, 1, 1, 1, 1 });
                        }
                        else
                        {
                            InitgdvCoaItem();
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                CommonFunction.ShowMsgBox(ex.Message);
                return;
            }
        }

===============

防止添加的数据主键冲突:

一开始没有主键就取查到的最大值+1,

int iSeq = InTag.coa_list[i].item_seq;
                            if (iSeq == 0)//传入的Seq为空(0)时,取数据库中最大的+1,否则直接保存
                            {
                                List uQcmcoaitemlist = ctx.UQcmcoaitem.Where(t => t.PkgNoticeNo == sPkgId && t.Factory == sFactory).OrderByDescending(t=>t.ItemSeq).ToList();
                                if (uQcmcoaitemlist != null)
                                {
                                    iSeq = uQcmcoaitemlist[0].ItemSeq + 1;
                                }
                                else
                                {
                                    iSeq = 1;
                                }
                            }
                            UQcmcoaitem uQcmcoaItem = new UQcmcoaitem
                            {
                                PkgNoticeNo = sPkgId,
                                Factory = sFactory,
                                ItemSeq = iSeq,
                                TestingResult =InTag.coa_list[i].testing_result,

                                TestingItem = InTag.coa_list[i].testing_item,
                                TestingSpec = InTag.coa_list[i].testing_specification,
                                TestingMethod = InTag.coa_list[i].testing_method,
                                Dimens = InTag.coa_list[i].dimens,
                                CreateTime = DBGV._dbc.DB_GetSysTime(),
                                CreateUserId = InTag._cmn_in._user_id
                            };
                            ctx.UQcmcoaitem.Add(uQcmcoaItem);

但是当添加多条Seq=0的数据时,从数据库查出的最大值+1就会使得要添加的这几天数据的主键冲突,因为事务还没提交,Seq都是Max+1

解决方法:在循环外面加一个int变量(count=0),每次Max+1后,再加上count:

 int count = 0;
for (int i = 0; i < InTag.coa_list.Length; i++)
{
                      if (InTag.coa_list[i].step == 'I')
                        {
                            int iSeq = InTag.coa_list[i].item_seq;
                            if (iSeq == 0)
                            {
                                List uQcmcoaitemlist = ctx.UQcmcoaitem.Where(t => t.PkgNoticeNo == sPkgId && t.Factory == sFactory).OrderByDescending(t=>t.ItemSeq).ToList();
                                if (uQcmcoaitemlist != null)
                                {
                                    iSeq = uQcmcoaitemlist[0].ItemSeq + 1+count;
                                    count++;
                                }
                                else
                                {
                                    iSeq = 1;
                                }
                            }
                            UQcmcoaitem uQcmcoaItem = new UQcmcoaitem
                            {
                                PkgNoticeNo = sPkgId,
                                Factory = sFactory,
                                ItemSeq = iSeq,
                                TestingResult =InTag.coa_list[i].testing_result,

                                TestingItem = InTag.coa_list[i].testing_item,
                                TestingSpec = InTag.coa_list[i].testing_specification,
                                TestingMethod = InTag.coa_list[i].testing_method,
                                Dimens = InTag.coa_list[i].dimens,
                                CreateTime = DBGV._dbc.DB_GetSysTime(),
                                CreateUserId = InTag._cmn_in._user_id
                            };
                            ctx.UQcmcoaitem.Add(uQcmcoaItem);
                        }
                        else
                        {
                            sMsgCode = "QCM-0004";
                            return GlobalConstant.FAIL;
                        }
                    }
                    ctx.SaveChanges();
                    transaction.Commit();

GridLookUpEdit下拉列表的高度设置:

将properties中的AutoHeight设置为false,再设置size的值

怎么防止下拉列表控件的EditvalueChanged事件进入死循环

到此,相信大家对“怎么防止下拉列表控件的EditvalueChanged事件进入死循环”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


本文题目:怎么防止下拉列表控件的EditvalueChanged事件进入死循环
网页地址:http://ybzwz.com/article/ihejee.html