Figure 7 Filtering
the Products
กก
// Get the selected category and cast it back to the Category class
Category oCat = (Category)cboCategory.SelectedItem;
// Create a DataView that filters the Products DataTable by the
// selected category
DataView oDV = new DataView(this.m_oDs.Tables["Products"],
"CategoryID = " +
Convert.ToString(oCat.CategoryID), "ProductName",
DataViewRowState.CurrentRows);
// Clear all bindings
cboProduct.DataBindings.Clear();
txtUnitPrice.DataBindings.Clear();
txtUnitsInStock.DataBindings.Clear();
txtUnitsOnOrder.DataBindings.Clear();
txtReorderLevel.DataBindings.Clear();
// Bind the DataView to the controls
cboProduct.DataSource = oDV;
cboProduct.DisplayMember = "ProductName";
cboProduct.ValueMember = "ProductID";
txtUnitPrice.DataBindings.Add("Text", oDV, "UnitPrice");
txtUnitsInStock.DataBindings.Add("Text", oDV, "UnitsInStock");
txtUnitsOnOrder.DataBindings.Add("Text", oDV, "UnitsOnOrder");
txtReorderLevel.DataBindings.Add("Text", oDV, "ReorderLevel");
// Select the first Product
cboProduct.SelectedIndex = 0;