示例#1
0
        private void FindRoutine()
        {
            gvwCourse.BeginUpdate();
            try
            {
                if (txtSearch.Text.Trim() == "")
                {
                    return;
                }

                //Creating Temp. Table
                DataTable Tempdtbl = new DataTable("TEMPTABLE");
                Tempdtbl = dtbl.Copy();
                dtbl.Rows.Clear();


                DataRowCollection CollSearchRow = Tempdtbl.Rows;
                bool   boolFound    = false;
                string strCellVal   = "";
                int    intMaxColCtr = 0;
                string strFindText  = txtSearch.Text.Trim();

                if (strFindText.EndsWith(".00"))
                {
                    strFindText = strFindText.Substring(0, strFindText.Length - 3);
                }
                if (strFindText.EndsWith(".0"))
                {
                    strFindText = strFindText.Substring(0, strFindText.Length - 2);
                }

                if (chk_AdvanceSearch.Checked)
                {
                    intMaxColCtr = Tempdtbl.Columns.Count - 1;
                }
                else
                {
                    intMaxColCtr = 3;
                }

                for (int intRowCtr = 0; intRowCtr <= CollSearchRow.Count - 1; intRowCtr++)
                {
                    DataRow SearchRow = CollSearchRow[intRowCtr];
                    boolFound  = false;
                    strCellVal = "";
                    for (int intColCtr = 1; intColCtr <= intMaxColCtr; intColCtr++)
                    {
                        strCellVal = SearchRow[intColCtr].ToString().Trim().ToUpper();
                        if (chk_Anywhere.Checked)
                        {
                            if (strCellVal.IndexOf(strFindText.ToUpper()) >= 0)
                            {
                                boolFound = true;
                                break;
                            }
                        }
                        else
                        {
                            if (strCellVal.StartsWith(strFindText.ToUpper()))
                            {
                                boolFound = true;
                                break;
                            }
                        }
                    }
                    if (boolFound)
                    {
                        boolFetch = false;
                        object[] obj = new object[dtbl.Columns.Count];
                        for (int i = 0; i < dtbl.Columns.Count; i++)
                        {
                            obj[i] = CollSearchRow[intRowCtr][i];
                        }
                        dtbl.Rows.Add(obj);
                    }
                }

                dtbl.AcceptChanges();
            }
            finally
            {
                gvwCourse.EndUpdate();
            }
        }