您好,登錄后才能下訂單哦!
本篇內容主要講解“怎么防止下拉列表控件的EditvalueChanged事件進入死循環”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么防止下拉列表控件的EditvalueChanged事件進入死循環”吧!
當 下拉列表控件選中后判定另一個為空,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<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);
但是當添加多條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<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下拉列表的高度設置:
將properties中的AutoHeight設置為false,再設置size的值
到此,相信大家對“怎么防止下拉列表控件的EditvalueChanged事件進入死循環”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。