private void txtSearch_TextChanged(object sender, TextChangedEventArgs e) { try { string typedString = txtSearch.Text; List<menu> autoList = new List<menu>(); autoList.Clear(); foreach (menu item in MenuList) { if(item.Name.ToString().ToLower().StartsWith(typedString.ToString().ToLower())) { autoList.Add(item); } } if (autoList.Count > 0) { lbSuggestion.ItemsSource = autoList; lbSuggestion.Visibility = Visibility.Visible; } else if (txtSearch.Text.Equals("")) { lbSuggestion.Visibility = Visibility.Collapsed; lbSuggestion.ItemsSource = null; } else { lbSuggestion.Visibility = Visibility.Collapsed; lbSuggestion.ItemsSource = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public class menu { public static string id; public static string name; public static string price; public menu(string id, string name, string price) { this.Id = id; this.Name = name; this.Price = price; } public string Id { get { return id; } set { id = value; } } public string Name { get { return name; } set { name = value; } } public string Price { get { return price; } set { price = value; } } }
List<menu> MenuList;
MenuList = new List<menu>(); DataSet ds = Globalvariables.Globals.select_load("Select menu_id,foodname,rprice from add_food_menu where foodname like '%" + txtSearch.Text + "%'"); if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string id = ds.Tables[0].Rows[i][0].ToString(); string name = ds.Tables[0].Rows[i][1].ToString(); string price = ds.Tables[0].Rows[i][2].ToString(); MenuList.Add(new menu(ds.Tables[0].Rows[i][0].ToString(),ds.Tables[0].Rows[i][1].ToString(),ds.Tables[0].Rows[i][2].ToString())); } }
"Select menu_id,foodname,rprice from add_food_menu where foodname like '%" + txtSearch.Text + "%'"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)