sgray128 1/24/2014 9:16:42 AM

Winforms - Gridiew Cell Validating

This code example demonstrates the Gridview Cell Validating Event. In this piece of code, we're only validating the new row.                       


Private Sub RadGridView2_CellValidating(sender As Object, e As Telerik.WinControls.UI.CellValidatingEventArgs) Handles RadGridView2.CellValidating
        If QuitValidating = True Then
            QuitValidating = False
            Me.RadListView1.Items.Add(" quit")
            Exit Sub
        End If
            If TypeOf (e.Row) Is GridViewNewRowInfo Then
                Dim strKitItem As String = ""
                If Trim(e.Column.Name.ToString) = "KitItemnmbr" Then
                    strKitItem = Trim(Common.toStr(e.Value))
                    If strKitItem = "" Then
                        Me.RadListView1.Items.Add(" empty item, exit")
                        Exit Sub
                    End If
                    'Exit Sub
                    'Populate desc
                    Dim oDT As DataTable
                    oDT = SPs.EMP_IV00101_SEL_byItemnmbr(strKitItem).getTable
                    If oDT.Rows.Count = 0 Then
                        FPCommon.Common.globalMessageBox("Item Number not found")
                        e.Cancel = True
                        Me.RadListView1.Items.Add(" item not found, exit")
                        Exit Sub
                    End If
                    Dim oRow As DataRow = oDT.Rows(0)
                    Dim ItemDesc As String = oRow("ItemDesc").ToString
                    e.Row.Cells("ITEMDESC").Value = ItemDesc
                    e.Row.Cells("Quantity").Value = 0
                    'Add Item Type
                    Dim oDT2 As DataTable = SPs.EMP_IV00101_SEL_byItemnmbr(strKitItem).getTable
                    For Each oRow2 As DataRow In oDT2.Rows
                        Dim Status2 As Integer = oRow2("ITEMTYPE")
                        Dim Status3 As String = ""
                        Select Case Status2
                            Case 1
                                Status3 = "Sales Inventory"
                            Case 2
                                Status3 = "Discontinued"
                            Case 3
                                Status3 = "Kit"
                            Case 4
                                Status3 = "Misc Charges"
                            Case 5
                                Status3 = "Services"
                            Case 6
                                Status3 = "Flat Fee"
                        End Select
                        Me.RadGridView2.MasterTemplate.CurrentRow.Cells("ITEMTYPE").Value = Status3
                        Exit For
                End If
                If e.Column.Name = "Quantity" Then
                    strKitItem = Trim(Common.toStr(Me.RadGridView2.CurrentRow.Cells("KitItemnmbr").Value))
                    Me.RadListView1.Items.Add(" quantity")
                    Dim decQuantity As Decimal = Common.toDecimal(e.Value)
                    Formstate = FormStateType.Dirty
                    If decQuantity > 0 And strKitItem = "" Then
                        Me.RadGridView2.MasterTemplate.CurrentRow.Cells("Quantity").Value = 0
                        e.Cancel = True
                        Me.RadListView1.Items.Add(" exit")
                        Exit Sub
                    End If
                    If e.Value Is Nothing And strKitItem = "" Then
                        Me.RadListView1.Items.Add(" exit3")
                        Exit Sub
                    End If
                    If decQuantity >= 0 And strKitItem = "" Then
                        Me.RadListView1.Items.Add(" exit2")
                        e.Cancel = True
                        Exit Sub
                    End If
                End If
            End If
            'If Trim(ItemDesc3) <> "" Then Me.RadGridView2.Rows(e.RowIndex).Cells(2).Value = ItemDesc3
            'ItemDesc3 = ""
            Me.RadListView1.Items.Add(" pass")
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, True)
        End Try
    End Sub