1. 程式人生 > >結束輸入按回車後直接搜尋的實現

結束輸入按回車後直接搜尋的實現

雙擊事件KeyPress

通過事件e檢測輸入字元, 當e.KeyChar == (char)13  時(13是回車,ASCII碼13)

 

 private void txtBatchID_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == (char)13)
                {
                    if (txtBatchID.Text != "")
                    {
                        //CommonFunction.ClearGridView(grdItemList, true);
                        //CommonFunction.ClearGridView(grdItemDefect, true);
                        //base.txtBatchID_KeyPress(sender, e);
                        if (ViewBatchInformation(txtBatchID.Text, "RESULT") == false)
                        {
                            return;
                        }
                        string sInspSet = CommonFunction.Trim(dtBatchInfo.Rows[2][1]);
                        int iInspSerVer = CommonFunction.ToInt(dtBatchInfo.Rows[2][3]);
                        if (sInspSet != "" && iInspSerVer != 0)
                        {
                            View_Attach_Insp_Item_List_Detail(txtBatchID.Text, sInspSet, iInspSerVer);
                        }
                        //檢驗計劃
                        DataTable dt2 = QCMLIST.ViewBatchInspectionPlanItemList(txtBatchID.Text);
                        if (dt2 != null)
                        {
                            DevGridControlHelper.BindData(gdcInspItemAll, dt2, new int[] { 1, -1, 1, -1, 1, 1 });
                            gdvInspItemAll.Columns["FLOW"].Group();
                            gdvInspItemAll.Columns["OPER"].Group();
                            gdvInspItemAll.ExpandAllGroups();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonFunction.ShowMsgBox(ex.Message);
            }
        }

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

  private void txtBatchID_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == (char)13)
                {
                    if (txtBatchID.Text != "")
                    {
                        //CommonFunction.ClearGridView(grdItemList, true);
                        //CommonFunction.ClearGridView(grdItemDefect, true);
                        //base.txtBatchID_KeyPress(sender, e);
                        if (BindGV() == false)
                        {
                            return;
                        }

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