using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Query;

namespace MyWinFormApp
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
      cbCategories.SelectedIndex = 0;      
    }

    private void cbCategories_SelectedIndexChanged(object sender, EventArgs e)
    {
      if ((sender as ComboBox).SelectedValue != null)
      {
        IObjectScope scope = NorthwindProvider.ObjectScope();

        int? selectValue = (int?)(sender as ComboBox).SelectedValue;
        var filteredData = from product in scope.Extent<Product>()
                           where product.CategoryID == selectValue
                           select new
                           {
                             Product = product.ProductName,
                             QuantityPerUnit = product.QuantityPerUnit,
                             Category = product.Category.CategoryName
                           };
        gvProducts.DataSource = filteredData.ToList();
      }
    }
  }
}
