private void productSelectComboBox_SelectedIndexChanged(object sender, System.EventArgs e) { // get the selected product if (productSelectComboBox.SelectedItem == null) { return; } ProductEntity selectedProduct = (ProductEntity)productSelectComboBox.SelectedItem; _productFilter.Value = selectedProduct.ProductId; // select the customers CustomerCollection customers = new CustomerCollection(); // select the customers using the relations and the filter we defined customers.GetMulti(_productFilter, 0, _customerSorter, _relationsToWalk); // bind them customersDataGrid.DataSource = customers; // get scalar for amount of times this product is sold. OrderDetailCollection orderDetails = new OrderDetailCollection(); object scalarValue = orderDetails.GetScalar( OrderDetailFieldIndex.Quantity, null, AggregateFunction.Sum, (OrderDetailFields.ProductId == selectedProduct.ProductId)); int amountUnitSold = 0; if (scalarValue != System.DBNull.Value) { amountUnitSold = (int)scalarValue; } _amountUnitsSoldTextBox.Text = amountUnitSold.ToString(); }