public static void AddLastTextFirstInAutoCompleteStringCollection(AutoCompleteStringCollection autoCompleteStringCollection, string newValue) { if (!string.IsNullOrWhiteSpace(newValue)) { try { int indexOfText = autoCompleteStringCollection.IndexOf(newValue); //Does it exist from before, remove to put first if (indexOfText > -1) { autoCompleteStringCollection.RemoveAt(indexOfText); //Remove if exist, in not already first } autoCompleteStringCollection.Insert(0, newValue); //Add first while (autoCompleteStringCollection.Count > maxCount) { autoCompleteStringCollection.RemoveAt(maxCount); } } catch (Exception ex) { Logger.Error(ex); KryptonMessageBox.Show(ex.Message, "Syntax error...", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true); } } }
public void RemoveAtTest() { autoCol.Add("Item1"); autoCol.Add("Item2"); autoCol.RemoveAt(0); Assert.AreEqual(1, remove_event, "#G1"); Assert.AreEqual("Item1", value_event, "#G2"); Assert.AreEqual(1, autoCol.Count, "#G3"); Assert.AreEqual(true, autoCol.Contains("Item2"), "#G4"); }
void load_product_data() { String connectionString = "Data Source=avi-test-db.cbg17hlkwa4g.ap-south-1.rds.amazonaws.com;" + "Initial Catalog=shop_erp;" + "User id=admin;" + "Password=12345678;"; String SqlString = @"SELECT ProductName FROM Product"; cb_product.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cb_product.AutoCompleteSource = AutoCompleteSource.CustomSource; AutoCompleteStringCollection coll = new AutoCompleteStringCollection(); cb_product.Items.Clear(); for (int i = 0; i < coll.Count; i++) { coll.RemoveAt(0); } using (SqlConnection connection = new SqlConnection(connectionString)) { try { connection.Open(); SqlCommand cmd = new SqlCommand(SqlString, connection); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows == true) { while (dr.Read()) { String Sname = dr.GetString(0); coll.Add(Sname); cb_product.Items.Add(Sname); } } } catch (Exception error) { MessageBox.Show(error.Message, "Error!"); } finally { cb_product.AutoCompleteCustomSource = coll; connection.Close(); } } }
public static void UpdateServerHistory(string hostnameWithPort) { AutoCompleteStringCollection history = GetServerHistory(); if (!history.Contains(hostnameWithPort)) { while (history.Count >= 20) { history.RemoveAt(0); } history.Add(hostnameWithPort); Properties.Settings.Default.ServerHistory = history; TrySaveSettings(); } }
private void FillGuestSuggestions() { AutoCompleteStringCollection FNamesource = new AutoCompleteStringCollection(); FNamesource.AddRange(dtGuest.AsEnumerable().Select(r => r.Field <string>("FirstName")).ToArray()); //Remove null value FNamesource.RemoveAt(0); txtFirstName.AutoCompleteCustomSource = FNamesource; AutoCompleteStringCollection LNameSource = new AutoCompleteStringCollection(); LNameSource.AddRange(dtGuest.AsEnumerable().Select(r => r.Field <string>("LastName")).ToArray()); //Remove null value LNameSource.RemoveAt(0); txtLastName.AutoCompleteCustomSource = LNameSource; }
private void txtMain_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //Only keep 10 AutoComplete strings if (acsc.Count < 10) { //Add to collection acsc.Add(txtMain.Text); } else { //remove oldest acsc.RemoveAt(0); //Add to collection acsc.Add(txtMain.Text); } } }