Thursday, December 25, 2014

WPF Search from ListView

In DAL use code like this:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//Search Customer from listview
        public List<CustomerInfo> SearchCustomer(string searchValue)
        {
            dataContextObj = new JSMSEntities();

            List<CustomerInfo> customerInfoList = new List<CustomerInfo>();
            foreach (var p in (from c in dataContextObj.tbl_Customer 
                               where c.CustomerName.Contains(searchValue) || c.CustomerMobile.Contains(searchValue)
                               select c).Distinct())
            {
                CustomerInfo _customerInfoObj = new CustomerInfo();
                _customerInfoObj.Id = p.ID;
                _customerInfoObj.CustomerName = p.CustomerName;
                _customerInfoObj.CustomerAddress = p.CustomerAddress;
                _customerInfoObj.CustomerPhone = p.CustomerPhone;
                _customerInfoObj.CustomerMobile = p.CustomerMobile;
                _customerInfoObj.CustomerFax = p.CustomerFax;
                _customerInfoObj.CustomerEmail = p.CustomerEmail;
                _customerInfoObj.CustomerNote = p.CustomerNote;

                customerInfoList.Add(_customerInfoObj);
            }

            return customerInfoList;
        }

In BLL use code like this:

1
2
3
4
5
//BLL Search customer
        public List<CustomerInfo> SearchCustomer(string searchValue)
        {
            return customerInfoGetwayObj.SearchCustomer(searchValue);
        }

In xaml.cs file use code like this:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
//Search Customer
        private void txtCustomerSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            _customerInfoList = new List<CustomerInfo>();
            _customerInfoList = _customerInfManagerObj.SearchCustomer(txtCustomerSearch.Text);
            CustomerInfoListView.Items.Clear();

            if (_customerInfoList.Count > 0)
            {
                foreach (var item in _customerInfoList)
                {
                    CustomerInfoListView.Items.Add(item);
                }
            }
        }

No comments:

Post a Comment