private void ItemTextBox_TextChanged(object sender, EventArgs e) { try { string keyword = ItemDescTextBox.Text.TrimStart(); SqlCommand cmd = new SqlCommand("SELECT ItemDescription FROM ItemsDetail WHERE ItemDescription LIKE '%" + keyword + "%'", con); cmd.CommandType = CommandType.Text; SqlDataReader dr = cmd.ExecuteReader(); List<string> ItemSuggestionsList = null; if (dr.HasRows) { ItemSuggestionsList = new List<string>(); while (dr.Read()) { string row = ""; row = Convert.ToString(dr["ItemDescription"]); ItemSuggestionsList.Add(row); } ItemSuggestionsList.TrimExcess(); } if (dr != null) { dr.Close(); } string[] sugs = ItemSuggestionsList.ToArray(); ItemSuggestionsList.Clear(); //Create and initialise object source for AutocompleteStringCollection AutoCompleteStringCollection source = new AutoCompleteStringCollection(); source.AddRange(sugs); ItemDescTextBox.AutoCompleteCustomSource = source; ItemDescTextBox.AutoCompleteMode = AutoCompleteMode.Suggest; ItemDescTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource; } catch (Exception ex) { label1.Text="ex source: " + ex.Source + "\nex msg: " + ex.Message + "\nex stk trace: " + ex.StackTrace; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)