您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“怎么防止下拉列表控件的EditvalueChanged事件進(jìn)入死循環(huán)”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么防止下拉列表控件的EditvalueChanged事件進(jìn)入死循環(huán)”吧!
當(dāng) 下拉列表控件選中后判定另一個(gè)為空,return之前需要將該下拉列表清空,就又會(huì)觸發(fā)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("檢查批號(hào)不能為空"); InitgdvCoaItem(); gluCOATemplate.Text = ""; txtLotID.Focus(); return; } if (gluCOATemplate.Text == "") { CommonFunction.ShowMsgBox("請(qǐng)選擇模板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; } }
===============
防止添加的數(shù)據(jù)主鍵沖突:
一開(kāi)始沒(méi)有主鍵就取查到的最大值+1,
int iSeq = InTag.coa_list[i].item_seq; if (iSeq == 0)//傳入的Seq為空(0)時(shí),取數(shù)據(jù)庫(kù)中最大的+1,否則直接保存 { List<UQcmcoaitem> 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);
但是當(dāng)添加多條Seq=0的數(shù)據(jù)時(shí),從數(shù)據(jù)庫(kù)查出的最大值+1就會(huì)使得要添加的這幾天數(shù)據(jù)的主鍵沖突,因?yàn)槭聞?wù)還沒(méi)提交,Seq都是Max+1
解決方法:在循環(huán)外面加一個(gè)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<UQcmcoaitem> 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下拉列表的高度設(shè)置:
將properties中的AutoHeight設(shè)置為false,再設(shè)置size的值
到此,相信大家對(duì)“怎么防止下拉列表控件的EditvalueChanged事件進(jìn)入死循環(huán)”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。