// selects the current item private bool SelectItem() { try { // if the ListBox is not empty if (((this.listBox.Items.Count > 0) && (this.SelectedIndex > -1))) { //string[] arrValues = listBox.SelectedItem.ToString().Trim().Split('-'); //// set the Text of the TextBox to the selected item of the ListBox //if (arrValues.Length > 1) // this._Text = arrValues[1];//this.listBox.SelectedItem.ToString(); //else this._Text = this.listBox.SelectedItem.ToString(); this.Select(this.Text.Length, 0); SelectedIndex = 0; // and hide the ListBox this.HideSuggestionListBox(); } return(true); } catch { return(false); } finally { CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); } }
// This is a timecritical part // Fills/ refreshed the CurrentAutoCompleteList with appropreate candidates private void UpdateCurrentAutoCompleteList() { // the list of suggestions has to be refreshed so clear it CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); // an find appropreate candidates for the new CurrentAutoCompleteList in AutoCompleteList buildData(this.Text); //foreach (string Str in AutoCompleteList) //{ // // be casesensitive // if (CaseSensitive) // { // // search for the substring (equal to SQL Like Command) // if ((Str.IndexOf(this.Text) > -1)) // // Add candidates to new CurrentAutoCompleteList // { // CurrentAutoCompleteList.Add(Str.Split(splitChar)[1]); // CurrentAutoCompleteList_IDAndCode.Add(Str.Split(splitChar)[0]); // } // } // // or ignore case // else // { // // and search for the substring (equal to SQL Like Command) // if ((Str.ToLower().IndexOf(this.Text.ToLower()) > -1)) // // Add candidates to new CurrentAutoCompleteList // { // CurrentAutoCompleteList.Add(Str.Split(splitChar)[1]); // CurrentAutoCompleteList_IDAndCode.Add(Str.Split(splitChar)[0]); // } // } //} #region Excursus: Performance measuring of Linq queries // This is a simple example of speedmeasurement for Linq querries /* * CurrentAutoCompleteList.Clear(); * Stopwatch stopWatch = new Stopwatch(); * stopWatch.Start(); * // using Linq query seems to be slower (twice as slow) * var query = * from expression in this.AutoCompleteList * where expression.ToLower().Contains(this.Text.ToLower()) * select expression; * foreach (string searchTerm in query) * { * CurrentAutoCompleteList.Add(searchTerm); * } * stopWatch.Stop(); * // method (see below) for printing the performance values to console * PrintStopwatch(stopWatch, "Linq - Contains"); */ #endregion Excursus: Performance measuring of Linq queries // countinue to update the ListBox - the visual part UpdateListBoxItems(); }
public void ClearMe() { AllowTextChanged = false; this.Clear(); AllowChangedListBox = false; listBox.SelectedIndex = -1; AllowChangedListBox = true; CurrentAutoCompleteList.Clear(); setDefaultValue(); AllowTextChanged = true; this.HideSuggestionListBox(); }
// selects the current item private bool SelectItem() { try { if (GridView) { if (Utility.isValidGrid(_grid.grdListDrug)) { //string[] arrValues = listBox.SelectedItem.ToString().Trim().Split('-'); //// set the Text of the TextBox to the selected item of the ListBox //if (arrValues.Length > 1) // this.Text = arrValues[1];//this.listBox.SelectedItem.ToString(); //else _Text = _grid.grdListDrug.GetValue(DmucThuoc.Columns.TenThuoc).ToString(); this.Select(this.Text.Length, 0); AllowTextChanged = false; _grid.AllowedChanged = AllowTextChanged; _grid.grdListDrug.MoveFirst(); AllowTextChanged = true; } } else { // if the ListBox is not empty if (((this.listBox.Items.Count > 0) && (this.SelectedIndex > -1))) { //string[] arrValues = listBox.SelectedItem.ToString().Trim().Split('-'); //// set the Text of the TextBox to the selected item of the ListBox //if (arrValues.Length > 1) // this.Text = arrValues[1];//this.listBox.SelectedItem.ToString(); //else this.Text = this.listBox.SelectedItem.ToString(); this.Select(this.Text.Length, 0); SelectedIndex = 0; } } // and hide the ListBox this.HideSuggestionListBox(); return(true); } catch { return(false); } finally { CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); CurrentAutoCompleteList_IDThuockho.Clear(); } }
private void UpdateCurrentAutoCompleteList() { CurrentAutoCompleteList.Clear(); foreach (string Str in AutoCompleteList) { if (CaseSensitive) { if ((Str.IndexOf(this.Text) > -1)) { CurrentAutoCompleteList.Add(Str); } } else { if ((Str.ToLower().IndexOf(this.Text.ToLower()) > -1)) { CurrentAutoCompleteList.Add(Str); } } } #region Excursus: Performance measuring of Linq queries // This is a simple example of speedmeasurement for Linq querries /* * CurrentAutoCompleteList.Clear(); * Stopwatch stopWatch = new Stopwatch(); * stopWatch.Start(); * // using Linq query seems to be slower (twice as slow) * var query = * from expression in this.AutoCompleteList * where expression.ToLower().Contains(this.Text.ToLower()) * select expression; * foreach (string searchTerm in query) * { * CurrentAutoCompleteList.Add(searchTerm); * } * stopWatch.Stop(); * // method (see below) for printing the performance values to console * PrintStopwatch(stopWatch, "Linq - Contains"); */ #endregion Excursus: Performance measuring of Linq queries // countinue to update the ListBox - the visual part UpdateListBoxItems(); }
// This is a timecritical part // Fills/ refreshed the CurrentAutoCompleteList with appropreate candidates private void UpdateCurrentAutoCompleteList() { // the list of suggestions has to be refreshed so clear it CurrentAutoCompleteList = AutoCompleteList.Copy(); CurrentAutoCompleteList.Rows.Clear(); // an find appropreate candidates for the new CurrentAutoCompleteList in AutoCompleteList foreach (DataRow row in AutoCompleteList.Rows) { if (SearchText(row, this.Text)) { CurrentAutoCompleteList.ImportRow(row); } } #region Excursus: Performance measuring of Linq queries // This is a simple example of speedmeasurement for Linq querries /* * CurrentAutoCompleteList.Clear(); * Stopwatch stopWatch = new Stopwatch(); * stopWatch.Start(); * // using Linq query seems to be slower (twice as slow) * var query = * from expression in this.AutoCompleteList * where expression.ToLower().Contains(this.Text.ToLower()) * select expression; * foreach (string searchTerm in query) * { * CurrentAutoCompleteList.Add(searchTerm); * } * stopWatch.Stop(); * // method (see below) for printing the performance values to console * PrintStopwatch(stopWatch, "Linq - Contains"); */ #endregion Excursus: Performance measuring of Linq queries // countinue to update the ListBox - the visual part UpdateListBoxItems(); }
// This is a timecritical part // Fills/ refreshed the CurrentAutoCompleteList with appropreate candidates private void UpdateCurrentAutoCompleteList() { // the list of suggestions has to be refreshed so clear it CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); string myText = Utility.DoTrim(this.Text); if (myText == "") { myText = " "; } // an find appropreate candidates for the new CurrentAutoCompleteList in AutoCompleteList foreach (string Str in AutoCompleteList) { string _value = Str; if (CompareNoID && Str.IndexOf("#") >= 0) { _value = Str.Split('#')[1]; } string[] arrvalues = Str.Split(splitChar); if (arrvalues.Length > 1) { // be casesensitive if (CaseSensitive) { // search for the substring (equal to SQL Like Command) if ((_value.IndexOf(myText) > -1)) // Add candidates to new CurrentAutoCompleteList { CurrentAutoCompleteList.Add(arrvalues[1]); CurrentAutoCompleteList_IDAndCode.Add(arrvalues[0]); } } // or ignore case else { // and search for the substring (equal to SQL Like Command) if ((_value.ToLower().IndexOf(myText.ToLower()) > -1)) // Add candidates to new CurrentAutoCompleteList { CurrentAutoCompleteList.Add(arrvalues[1]); CurrentAutoCompleteList_IDAndCode.Add(arrvalues[0]); } } } } #region Excursus: Performance measuring of Linq queries // This is a simple example of speedmeasurement for Linq querries /* * CurrentAutoCompleteList.Clear(); * Stopwatch stopWatch = new Stopwatch(); * stopWatch.Start(); * // using Linq query seems to be slower (twice as slow) * var query = * from expression in this.AutoCompleteList * where expression.ToLower().Contains(this.Text.ToLower()) * select expression; * foreach (string searchTerm in query) * { * CurrentAutoCompleteList.Add(searchTerm); * } * stopWatch.Stop(); * // method (see below) for printing the performance values to console * PrintStopwatch(stopWatch, "Linq - Contains"); */ #endregion Excursus: Performance measuring of Linq queries if (CurrentAutoCompleteList.Count <= 0) { setDefaultValue(); } // countinue to update the ListBox - the visual part UpdateListBoxItems(); }
// shows the suggestions in ListBox beneath the TextBox // and fitting it into the TopLevelControl private void ShowSuggests() { if (!AllowTextChanged) { return; } // show only if MinTypedCharacters have been typed if (this.Text.Length >= MinTypedCharacters) { // prevent overlapping problems with other controls // while loading data there is nothing to draw, so suspend layout panel.SuspendLayout(); // user is typing forward, char has been added at the end of the former input if ((this.Text.Length > 0) && (this.oldText == this.Text.Substring(0, this.Text.Length - 1))) { //handle forward typing with refresh UpdateCurrentAutoCompleteList(); } // user is typing backward - char bas been removed else if ((this.oldText.Length > 0) && (this.Text == this.oldText.Substring(0, this.oldText.Length - 1))) { //handle backward typing with refresh UpdateCurrentAutoCompleteList(); } // something within has changed else { // handle other things like corrections in the middle of the input, clipboard pastes, etc. with refresh UpdateCurrentAutoCompleteList(); } if (((CurrentAutoCompleteList != null) && CurrentAutoCompleteList.Count > 0)) { // finally show Panel and ListBox // (but after refresh to prevent drawing empty rectangles) panel.Show(); // at the top of all controls panel.BringToFront(); listBox_SelectedIndexChanged(listBox, new EventArgs()); // then give the focuse back to the TextBox (this control) this.Focus(); } // or hide if no results else { this.HideSuggestionListBox(); } // prevent overlapping problems with other controls panel.ResumeLayout(true); if (Utility.DoTrim(this.Text) == "") { setDefaultValue(); } } // hide if typed chars <= MinCharsTyped else { AllowChangedListBox = false; listBox.SelectedIndex = -1; AllowChangedListBox = true; CurrentAutoCompleteList.Clear(); setDefaultValue(); this.HideSuggestionListBox(); } if (RaiseEventEnterWhenEmpty && _OnSelectionChanged != null) { _OnSelectionChanged(); } if (Utility.DoTrim(this.Text) == "" && RaiseEventEnterWhenEmpty && _OnEnterMe != null) { _OnEnterMe(); } }
// selects the current item private bool SelectItem() { try { // if the ListBox is not empty if (((this.listBox.Items.Count > 0) && (this.SelectedIndex > -1))) { //string[] arrValues = listBox.SelectedItem.ToString().Trim().Split('-'); //// set the Text of the TextBox to the selected item of the ListBox //if (arrValues.Length > 1) // this._Text = arrValues[1];//this.listBox.SelectedItem.ToString(); //else string[] arrValues = CurrentAutoCompleteList_IDAndCode[listBox.SelectedIndex].ToString().Trim().Split(splitCharIDAndCode); // set the Text of the TextBox to the selected item of the ListBox if (arrValues.Length == 2) { if (txtMyID != null) { txtMyID.Text = arrValues[0]; } if (txtMyID_Edit != null) { txtMyID_Edit.Text = arrValues[0]; } if (txtMyCode != null) { txtMyCode.Text = arrValues[1]; } if (txtMyCode_Edit != null) { txtMyCode_Edit.Text = arrValues[1]; } if (txtMyName != null) { txtMyName.Text = listBox.SelectedItem.ToString(); } if (txtMyName_Edit != null) { txtMyName_Edit.Text = listBox.SelectedItem.ToString(); } myCode = arrValues[1]; MyCode = myCode; if (TakeCode) { if (arrValues.Length > 1) { this._Text = arrValues[1]; } } else { this._Text = this.listBox.SelectedItem.ToString(); } } this.Select(this.Text.Length, 0); SelectedIndex = 0; // and hide the ListBox this.HideSuggestionListBox(); } return(true); } catch { return(false); } finally { CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); } }
private void buildData(string TenTp) { if (Utility.DoTrim(TenTp) != "") { TenTp = TenTp.TrimStart();//Tránh trường hợp nhập " hn" hệ thống không tìm được dữ liệu } TenTp = TenTp.Replace("'", ""); string _rowFilter = "1=1"; if (TenTp == "")// || TenTp.Length > 6) { CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); return; } if (TenTp != "" && TenTp.Trim() == "") { TenTp = " "; } dtData.DefaultView.RowFilter = "1=1"; //Tạm khóa lại //if (TenTp.Trim() != "") //{ // if (TenTp.Length == 1) // { // _rowFilter = " ShortcutTP like '%" + TenTp + "%' AND ShortcutXP='kx' AND ShortcutQH='kx'"; // } // if (TenTp.Length == 2) // { // _rowFilter = " ShortcutTP = '" + TenTp + "' AND ShortcutXP='kx' AND ShortcutQH='kx'"; // } // if (TenTp.Length == 3) // { // _rowFilter = " ShortcutTP like '%" + TenTp.Substring(2, 1) + // "%' AND ShortcutXP='kx' AND ShortcutQH = '" + TenTp.Substring(0, 2) + "'"; // } // if (TenTp.Length == 4) // { // _rowFilter = " ShortcutTP = '" + TenTp.Substring(2, 2) + "' AND ShortcutXP='kx' AND ShortcutQH = '" + // TenTp.Substring(0, 2) + "'"; // } // if (TenTp.Length == 5) // { // _rowFilter = " ShortcutTP like '%" + TenTp.Substring(4, 1) + "%' AND ShortcutXP ='" + // TenTp.Substring(0, 2) + "' AND ShortcutQH = '" + TenTp.Substring(2, 2) + "'"; // } // if (TenTp.Length == 6) // { // _rowFilter = " ShortcutTP = '" + TenTp.Substring(4, 2) + "' AND ShortcutXP='" + // TenTp.Substring(0, 2) + "' AND ShortcutQH = '" + TenTp.Substring(2, 2) + "'"; // } // //_rowFilter = " Shortcut like '%" + TenTp + "%' OR Value like '%" + TenTp + "'%"; // // string.Format(", LQuickSearch.Columns.Shortform); // m_DC.DefaultView.RowFilter = _rowFilter; //} if (Utility.DoTrim(TenTp) != "") { if (Utility.DoTrim(TenTp).Contains(" ") || Utility.CheckUnicode(TenTp) || Utility.DoTrim(TenTp).Length > 6) { _rowFilter = "1=0"; } else if (Utility.DoTrim(TenTp).Contains(" ") || Utility.DoTrim(TenTp).Length > 6)//Gõ trực tiếp tên thay vì gõ tắt // if (Utility.DoTrim(TenTp).Contains(" ") || Utility.CheckUnicode(TenTp) || Utility.DoTrim(TenTp).Length > 6)//Gõ trực tiếp tên thay vì gõ tắt { _rowFilter = " Value like '%" + TenTp + "%' Or ComparedValue like '%" + TenTp + "%'"; } else { if (TenTp.Length == 1) { _rowFilter = " ShortcutTP like '%" + TenTp + "%' AND ShortcutXP='kx' AND ShortcutQH='kx'"; } if (TenTp.Length == 2) { _rowFilter = " ShortcutTP = '" + TenTp + "' AND ShortcutXP='kx' AND ShortcutQH='kx'"; } if (TenTp.Length == 3) { _rowFilter = " ShortcutTP like '%" + TenTp.Substring(2, 1) + "%' AND ShortcutQH = '" + TenTp.Substring(0, 2) + "'"; } if (TenTp.Length == 4) { _rowFilter = " ShortcutTP = '" + TenTp.Substring(2, 2) + "' AND ShortcutQH = '" + TenTp.Substring(0, 2) + "'"; } if (TenTp.Length == 5) { _rowFilter = " ShortcutTP like '%" + TenTp.Substring(4, 1) + "%' AND ShortcutXP ='" + TenTp.Substring(0, 2) + "' AND ShortcutQH = '" + TenTp.Substring(2, 2) + "'"; } if (TenTp.Length == 6) { _rowFilter = " ShortcutTP = '" + TenTp.Substring(4, 2) + "' AND ShortcutXP='" + TenTp.Substring(0, 2) + "' AND ShortcutQH = '" + TenTp.Substring(2, 2) + "'"; } } //_rowFilter = " Shortcut like '%" + TenTp + "%' OR Value like '%" + TenTp + "'%"; // string.Format(", LQuickSearch.Columns.Shortform); dtData.DefaultView.RowFilter = _rowFilter; } dtData.AcceptChanges(); for (int i = 0; i <= dtData.DefaultView.Count - 1; i++) { string ItemsValue = Utility.sDbnull(dtData.DefaultView[i]["Value"], ""); CurrentAutoCompleteList.Add(ItemsValue); CurrentAutoCompleteList_IDAndCode.Add(ItemsValue); } }
// selects the current item private bool SelectItem() { try { if (GridView) { if (Utility.isValidGrid(_grid.grdListDrug)) { //string[] arrValues = listBox.SelectedItem.ToString().Trim().Split('-'); //// set the Text of the TextBox to the selected item of the ListBox //if (arrValues.Length > 1) // this._Text = arrValues[1];//this.listBox.SelectedItem.ToString(); //else _Text = _grid.grdListDrug.GetValue(DmucThuoc.Columns.TenThuoc).ToString(); MyID = Utility.Int32Dbnull(_grid.grdListDrug.GetValue("id_thuoc"), "-1"); MyCode = Utility.sDbnull(_grid.grdListDrug.GetValue("id_thuoc"), "-1"); id_thuockho = Utility.Int32Dbnull(_grid.grdListDrug.CurrentRow.Cells["id_thuockho"].Value, -1); this.Select(this.Text.Length, 0); AllowTextChanged = false; _grid.AllowedChanged = AllowTextChanged; _grid.grdListDrug.MoveFirst(); AllowTextChanged = true; } } else { // if the ListBox is not empty if (((this.listBox.Items.Count > 0) && (this.SelectedIndex > -1))) { if (CurrentAutoCompleteList.Count != CurrentAutoCompleteList_IDAndCode.Count || listBox.SelectedIndex < 0) { return(false); } string[] arrValues = CurrentAutoCompleteList_IDAndCode[listBox.SelectedIndex].ToString().Trim().Split(splitCharIDAndCode); // set the Text of the TextBox to the selected item of the ListBox if (arrValues.Length == 2) { if (txtMyID != null) { txtMyID.Text = arrValues[0]; } if (txtMyID_Edit != null) { txtMyID_Edit.Text = arrValues[0]; } if (txtMyCode != null) { txtMyCode.Text = arrValues[1]; } if (txtMyCode_Edit != null) { txtMyCode_Edit.Text = arrValues[1]; } MyID = arrValues[0]; MyCode = arrValues[1]; //find id_thuockho //DataRow[] arrDr = dtData.Select("id_thuoc=" + MyID); //if (arrDr.Length > 0) id_thuockho = Utility.Int32Dbnull(CurrentAutoCompleteList_IDThuockho[listBox.SelectedIndex], -1); if (txtMyName != null) { txtMyName.Text = listBox.SelectedItem.ToString(); } if (txtMyName_Edit != null) { txtMyName_Edit.Text = listBox.SelectedItem.ToString(); } } this._Text = this.listBox.SelectedItem.ToString(); this.Select(this.Text.Length, 0); SelectedIndex = 0; } } // and hide the ListBox this.HideSuggestionListBox(); return(true); } catch { return(false); } finally { CurrentAutoCompleteList.Clear(); CurrentAutoCompleteList_IDAndCode.Clear(); CurrentAutoCompleteList_IDThuockho.Clear(); } }