TelerikDeveloper.com

TelerikDeveloper.com

sgray128 4/6/2012 4:05:29 PM

Winforms- UserAddingRow example

Like most of our articles, you're not going to find in-depth explanations of complicated code paradigms here...

The intent is to post code examples that will enable rapid development. If you have a code example for something, you don't have to go searching for it.

This is an example of how to use the Telerik UserAddingRow event



    Private Sub RadGridView1_UserAddingRow(ByVal sender As Object,
            ByVal e As Telerik.WinControls.UI.GridViewRowCancelEventArgsHandles RadGridView1.UserAddingRow
 
        Try
            'There might be more than one row
            For Each oRow As GridViewDataRowInfo In e.Rows
                Dim strPrcLevel As String = oRow.Cells("prclevel").Value
                Dim strItemNumber As String = oRow.Cells("itemnmbr").Value
                Dim strUofM As String = oRow.Cells("UofM").Value
                Dim decUnitPrice As Decimal = oRow.Cells("unitprce").Value
 
                'validate
                If strPrcLevel = "" Then
                    GlobalMessageBox("Invalid price level")
                    e.Cancel = True
                    Exit Sub
                End If
 
                If strItemNumber = "" Then
                    GlobalMessageBox("Invalid itemnmbr")
                    e.Cancel = True
                    Exit Sub
                End If
 
                'data access code.
                'We use the DynDeveloper Data Access classes, located here:
                'http://dyndeveloper.com/Menus/SQLScriptsThatWriteScripts.aspx
                SPs.FP_IV00108QuotedPrices_INS(strPrcLevel, strItemNumber, strUofM, decUnitPrice, appUser.Db).execute()
            Next
        Catch ex As Exception
            GlobalErrorHandler(ex)
        End Try
    End Sub

Code to get the data in the new row:

intMasterOrderItemFK = Me.RadGridView1.MasterView.TableAddNewRow.Cells("intMasterOrderItemFK").Value