private void BindLocationComboBox(ComboBox cbLocation, Constant.LocationType locationType, string parentId = "") { var uow = new UnitOfWork <Location>(dbContext); var locations = uow.Repository.GetAll(); if (string.IsNullOrEmpty(parentId)) { locations = locations .Where(l => l.LocationType == locationType) .OrderBy(l => l.Name); } else { locations = locations .Where(l => l.LocationType == locationType && l.ParentId == parentId) .OrderBy(l => l.Name); } AutoCompleteStringCollection autoCompleteCollection = new AutoCompleteStringCollection(); Dictionary <string, string> dsLocations = new Dictionary <string, string>(); dsLocations.Add("0", "--Pilih--"); foreach (var loc in locations) { dsLocations.Add(loc.Id, loc.Name); autoCompleteCollection.Add(loc.Name); } cbLocation.DataSource = new BindingSource(dsLocations, null); cbLocation.DisplayMember = "Value"; cbLocation.ValueMember = "Key"; cbLocation.AutoCompleteCustomSource = autoCompleteCollection; }
private int BindDataListView(ListView parentListView, Constant.LocationType locationType, string parentId = "") { var uow = new UnitOfWork <Location>(dbContext); IQueryable <Location> locations; if (string.IsNullOrEmpty(parentId)) { locations = uow.Repository.GetAll().Where(l => l.LocationType == locationType) .OrderBy(l => l.Name); } else { locations = uow.Repository.GetAll().Where(l => l.LocationType == locationType && l.ParentId == parentId) .OrderBy(l => l.Name); } parentListView.Items.Clear(); parentListView.Columns[0].Width = 0; parentListView.Columns[1].Width = parentListView.Width; foreach (var loc in locations) { var listViewItem = new ListViewItem(loc.Id); listViewItem.SubItems.Add(loc.Name); parentListView.Items.Add(listViewItem); } return(locations.Count()); }