private void GetAutoCompleteFilter() { CoffeeDAO dao = new CoffeeDAO(); List <CoffeeDTO> list = dao.getCoffeeList(); var source = new AutoCompleteStringCollection(); foreach (var dto in list) { source.Add(dto.Name); } txtFilter.AutoCompleteCustomSource = source; txtFilter.AutoCompleteMode = AutoCompleteMode.Suggest; txtFilter.AutoCompleteSource = AutoCompleteSource.CustomSource; }
private void txtFilter_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { listCoffee.DataSource = null; string sFilter = txtFilter.Text; listCoffee.BeginUpdate(); listCoffee.Items.Clear(); CoffeeDAO dao = new CoffeeDAO(); List <CoffeeDTO> list = dao.getCoffeeList(); List <CoffeeDTO> filterList = new List <CoffeeDTO>(); foreach (var dto in list) { if (dto.Name.ToLower().Contains(sFilter.ToLower())) { filterList.Add(dto); } } bsCoffee.DataSource = filterList; listCoffee.DataSource = bsCoffee; listCoffee.DisplayMember = "Name"; listCoffee.EndUpdate(); } }
private void LoadList() { CoffeeDAO dao = new CoffeeDAO(); List <CoffeeDTO> list = dao.getCoffeeList(); bsCoffee.DataSource = list; lbName.DataBindings.Clear(); txtDesc.DataBindings.Clear(); TotalPrice.DataBindings.Clear(); lbName.DataBindings.Add("Text", bsCoffee, "Name"); txtDesc.DataBindings.Add("Text", bsCoffee, "Description"); txtPrice.DataBindings.Add("Text", bsCoffee, "Price"); TotalPrice.DataBindings.Add("Text", bsCoffee, "Price"); listCoffee.DataSource = bsCoffee; listCoffee.DisplayMember = "Name"; /*foreach (CoffeeDTO item in list) * { * listCoffee.Items.Add(item.Name); * }*/ }