Hello..
I'm trying to filter data in a datagrid depending on what the user enters in a text box which contains an order id. I'm using WPF. I understand the following works:
private void btnFindByOrderID_Click(object sender, RoutedEventArgs e) { if (txtFind.Text != string.Empty) { source.Filter = filter; } else { MessageBox.Show("Find text box is empty!"); txtFind.Focus(); } } private bool filter(object item) { int val = int.Parse(txtFind.Text); Order o = (item as Order); if (o.OrderID == val) { return true; } return false; }
No problem with the code above, however, I don't want all the code in the same page. I will like the code in a class from a different project, which of course is referenced in the main project. I'm trying to separate all the data from the main page. hence,
I though this would work, however, as I was debugging, it seems that is sending all the records, not only the one record that is supposed to. Here is my code in separate projects:
CODE IN MY MAIN PAGE:
private void btnFindByOrderID_Click(object sender, RoutedEventArgs e) { if (txtFind.Text != string.Empty) { source.Filter = App.StoreDb.filterByOrderID; } else { MessageBox.Show("Find text box is empty!"); txtFind.Focus(); } }
CODE IN ANOTHER PROJECT CALLED NorthwindData, CLASS StoreDB:
public bool filterByOrderID(object item) { Order order = item as Order; int ordertofind = order.OrderID; if (order.OrderID == ordertofind) { return true; } return false; }
Any help will be appreciated...
Guisselle