Imports Telerik.OpenAccess
Imports _2_ORM_Model
Public Class Form1

    Public Sub New()
        InitializeComponent()
        cbCategories.SelectedIndex = 0
    End Sub



    Private Sub cbCategories_SelectedIndexChanged(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles cbCategories.SelectedIndexChanged

        'If (TryCast(sender, ComboBox)).SelectedValue <> Nothing Then
        '    Me.Text = (TryCast(sender, ComboBox)).SelectedValue.ToString()
        'End If

        'If (TryCast(sender, ComboBox)).SelectedValue <> Nothing Then
        '    Dim scope As IObjectScope = NorthwindProvider.ObjectScope()

        '    Dim selectValue As System.Nullable(Of Integer) = _
        '       DirectCast((TryCast(sender, ComboBox)).SelectedValue,  _
        '       System.Nullable(Of Integer))

        '    Dim filteredData = _
        '       From product In scope.Extent(Of Product)() _
        '       Where product.CategoryID = selectValue _
        '       Select product
        '    gvProducts.DataSource = filteredData.ToList()
        'End If

        If (TryCast(sender, ComboBox)).SelectedValue IsNot Nothing Then
            Dim scope As IObjectScope = NorthwindProvider.ObjectScope()

            Dim selectValue As Nullable(Of Integer) = _
               CType((TryCast(sender, ComboBox)).SelectedValue, Nullable(Of Integer))

            Dim filteredData = _
               From product In scope.Extent(Of Product)() _
                  Where product.CategoryID.Equals(selectValue) _
                  Select _
                   ProductName = product.ProductName, _
                   QuantityPerUnit = product.QuantityPerUnit, _
                   CategoryName = product.Category.CategoryName
            gvProducts.DataSource = filteredData.ToList()

        End If

    End Sub
End Class
