Iterate through a filtered grid with a "Selected" column

This example shows a form that has a filtered grid with a "Selected" column, like this:

The code example below shows how to iterate through all of the filtered, selected rows. We first loop through the filtered rows, so if a non visible row is 'Selected' it will not be processed. Then we check to see if the filtered row is 'Selected', and process it. 

 

We'll show the code behind, and then the Designer code. 

Imports Telerik.WinControls.UI
 
Public Class ItemCostUpdate
    Private Sub ItemCostUpdate_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim strError As String = ""
        Try
            SetupGrid()
            BindGrid()
 
            FormState = FormStateType.Percent
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, True)
        End Try
 
    End Sub
 
    Private Sub BindGrid()
        Dim strError As String = ""
        Try
            Me.RadGridView1.DataSource = SPs.fp_ItemCostUpdate(App.ConnectionString).getTable
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, True)
        End Try
 
    End Sub
 
    Private Sub SetupGrid()
        Dim strError As String = ""
        Try
            'create the new grid object
            Dim oTelerikGrid As New FPTelerikCommon.TelerikGrid
 
            'add new columns by type and name to the grid...verified in SQL server
            Dim oCol As GridViewCheckBoxColumn = oTelerikGrid.createGridViewCheckBoxColumn("", "Selected", True, False, 70)
            oCol.EnableHeaderCheckBox = True
            Me.RadGridView1.Columns.Add(oCol)
 
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("Item Number", "itemnmbr", 11, 250, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("Class Code", "itmclscd", 11, 70, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("OversizeFactor", "OversizeFactor", 11, 70, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("VENDORID", "VENDORID", 11, 110, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("STNDCOST", "STNDCOST", 11, 70, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("CURRCOST", "CURRCOST", 11, 70, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("USCATVLS_5", "USCATVLS_5", 11, 70, True, True))
            Me.RadGridView1.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("New Price", "NewPrice", 11, 70, True, False))
 
 
            'set the grid properties
            Me.RadGridView1.EnableGrouping = False
            Me.RadGridView1.AllowAddNewRow = False
            Me.RadGridView1.AllowDeleteRow = False
            Me.RadGridView1.AllowEditRow = True
            Me.RadGridView1.EnableFiltering = True
            Me.RadGridView1.MasterTemplate.EnableSorting = True
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, True)
        End Try
    End Sub
 
    Private Sub ItemCostUpdate_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim strError As String = ""
        Try
            Dispose()
            GC.Collect()
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, True)
        End Try
 
    End Sub
    Private Sub rdoFixedAmount_CheckStateChanged(sender As Object, e As EventArgs) Handles rdoFixedAmount.CheckStateChanged
        Dim strError As String = ""
        Try
            If rdoFixedAmount.IsChecked Then
                FormState = FormStateType.Fixed
            Else
                FormState = FormStateType.Percent
            End If
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, True)
        End Try
 
    End Sub
    Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles btnProcess.Click
        Dim strError As String = ""
        Try
            Dim bSelected As Boolean
            For Each orow As GridViewRowInfo In RadGridView1.ChildRows
                bSelected = orow.Cells("Selected").Value
                If bSelected Then
                    'this will iterate through all the filtered, selected items
                    Debug.WriteLine(orow.Cells("itemnmbr").Value)
                End If
 
            Next
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, True)
        End Try
 
    End Sub
 
    Private Enum FormStateType
        Percent
        Fixed
    End Enum
    Private _FormState As FormStateType
    Private WriteOnly Property FormState() As FormStateType
        Set(ByVal value As FormStateType)
            _FormState = value
 
            Select Case value
                Case FormStateType.Percent
                    Me.spnFixedAmount.Enabled = False
                    Me.spnPercentAmount.Enabled = True
                Case FormStateType.Fixed
                    Me.spnFixedAmount.Enabled = True
                    Me.spnPercentAmount.Enabled = False
            End Select
        End Set
    End Property
 
End Class

 

Designer

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class ItemCostUpdate
    Inherits System.Windows.Forms.Form
 
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim TableViewDefinition1 As Telerik.WinControls.UI.TableViewDefinition = New Telerik.WinControls.UI.TableViewDefinition()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ItemCostUpdate))
        Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView()
        Me.ToolStrip1 = New System.Windows.Forms.ToolStrip()
        Me.btnProcess = New System.Windows.Forms.ToolStripButton()
        Me.rdoPercent = New Telerik.WinControls.UI.RadRadioButton()
        Me.rdoFixedAmount = New Telerik.WinControls.UI.RadRadioButton()
        Me.spnPercentAmount = New Telerik.WinControls.UI.RadSpinEditor()
        Me.spnFixedAmount = New Telerik.WinControls.UI.RadSpinEditor()
        Me.Label1 = New System.Windows.Forms.Label()
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.ToolStrip1.SuspendLayout()
        CType(Me.rdoPercent, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.rdoFixedAmount, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.spnPercentAmount, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.spnFixedAmount, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'RadGridView1
        '
        Me.RadGridView1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
            Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.RadGridView1.Location = New System.Drawing.Point(12, 119)
        '
        '
        '
        Me.RadGridView1.MasterTemplate.ViewDefinition = TableViewDefinition1
        Me.RadGridView1.Name = "RadGridView1"
        Me.RadGridView1.Size = New System.Drawing.Size(994, 476)
        Me.RadGridView1.TabIndex = 0
        '
        'ToolStrip1
        '
        Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.btnProcess})
        Me.ToolStrip1.Location = New System.Drawing.Point(0, 0)
        Me.ToolStrip1.Name = "ToolStrip1"
        Me.ToolStrip1.Size = New System.Drawing.Size(1018, 25)
        Me.ToolStrip1.TabIndex = 1
        Me.ToolStrip1.Text = "ToolStrip1"
        '
        'btnProcess
        '
        Me.btnProcess.Image = CType(resources.GetObject("btnProcess.Image"), System.Drawing.Image)
        Me.btnProcess.ImageTransparentColor = System.Drawing.Color.Magenta
        Me.btnProcess.Name = "btnProcess"
        Me.btnProcess.Size = New System.Drawing.Size(67, 22)
        Me.btnProcess.Text = "Process"
        '
        'rdoPercent
        '
        Me.rdoPercent.CheckState = System.Windows.Forms.CheckState.Checked
        Me.rdoPercent.Location = New System.Drawing.Point(12, 58)
        Me.rdoPercent.Name = "rdoPercent"
        Me.rdoPercent.Size = New System.Drawing.Size(58, 18)
        Me.rdoPercent.TabIndex = 4
        Me.rdoPercent.Text = "Percent"
        Me.rdoPercent.ToggleState = Telerik.WinControls.Enumerations.ToggleState.[On]
        '
        'rdoFixedAmount
        '
        Me.rdoFixedAmount.Location = New System.Drawing.Point(12, 84)
        Me.rdoFixedAmount.Name = "rdoFixedAmount"
        Me.rdoFixedAmount.Size = New System.Drawing.Size(90, 18)
        Me.rdoFixedAmount.TabIndex = 5
        Me.rdoFixedAmount.TabStop = False
        Me.rdoFixedAmount.Text = "Fixed Amount"
        '
        'spnPercentAmount
        '
        Me.spnPercentAmount.DecimalPlaces = 1
        Me.spnPercentAmount.Location = New System.Drawing.Point(113, 57)
        Me.spnPercentAmount.Name = "spnPercentAmount"
        Me.spnPercentAmount.ShowUpDownButtons = False
        Me.spnPercentAmount.Size = New System.Drawing.Size(53, 20)
        Me.spnPercentAmount.TabIndex = 6
        Me.spnPercentAmount.TextAlignment = System.Windows.Forms.HorizontalAlignment.Right
        '
        'spnFixedAmount
        '
        Me.spnFixedAmount.DecimalPlaces = 1
        Me.spnFixedAmount.Location = New System.Drawing.Point(113, 83)
        Me.spnFixedAmount.Name = "spnFixedAmount"
        Me.spnFixedAmount.ShowUpDownButtons = False
        Me.spnFixedAmount.Size = New System.Drawing.Size(53, 20)
        Me.spnFixedAmount.TabIndex = 7
        Me.spnFixedAmount.TextAlignment = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(12, 36)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(196, 13)
        Me.Label1.TabIndex = 8
        Me.Label1.Text = "Adjust the cost of the checked items by:"
        '
        'ItemCostUpdate
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(1018, 607)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.spnFixedAmount)
        Me.Controls.Add(Me.spnPercentAmount)
        Me.Controls.Add(Me.rdoFixedAmount)
        Me.Controls.Add(Me.rdoPercent)
        Me.Controls.Add(Me.ToolStrip1)
        Me.Controls.Add(Me.RadGridView1)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "ItemCostUpdate"
        Me.Text = "Item Cost Update"
        CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ToolStrip1.ResumeLayout(False)
        Me.ToolStrip1.PerformLayout()
        CType(Me.rdoPercent, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.rdoFixedAmount, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.spnPercentAmount, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.spnFixedAmount, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()
 
    End Sub
 
    Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView
    Friend WithEvents ToolStrip1 As ToolStrip
    Friend WithEvents btnProcess As ToolStripButton
    Friend WithEvents rdoPercent As Telerik.WinControls.UI.RadRadioButton
    Friend WithEvents rdoFixedAmount As Telerik.WinControls.UI.RadRadioButton
    Friend WithEvents spnPercentAmount As Telerik.WinControls.UI.RadSpinEditor
    Friend WithEvents spnFixedAmount As Telerik.WinControls.UI.RadSpinEditor
    Friend WithEvents Label1 As Label
End Class

 

 

 

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences