Imports Telerik.OpenAccess
Imports Telerik.WinControls
Imports Telerik.WinControls.UI
Imports _2_ORM_Model

Public Class Form1

    Public Sub New()
        InitializeComponent()

        ' hide the 'Add new row' button
        gvProducts.MasterGridViewTemplate.AllowAddNewRow = False
        ' SelectedIndex is already '0', so work around by setting to 
        ' 'no selection', i.e. '-1', then first item '0'
        cbCategories.SelectedIndex = -1
        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, RadComboBox)).SelectedValue <> Nothing Then
            Dim scope As IObjectScope = NorthwindProvider.ObjectScope()

            Dim selectValue As System.Nullable(Of Integer) = _
      DirectCast((TryCast(sender, RadComboBox)).SelectedValue,  _
      System.Nullable(Of Integer))
            Dim filteredData = _
              From product In scope.Extent(Of Product)() _
               Where product.CategoryID = selectValue

            gvProducts.DataSource = filteredData.ToList()
            gvProducts.MasterGridViewTemplate.BestFitColumns()

        End If
    End Sub
End Class
