TelerikDeveloper.com

TelerikDeveloper.com

sgray128 10/20/2014 3:11:32 PM

Winforms - GridViewCheckBoxColumn

Common code for the GridViewCheckBoxColumn


Add the Header 'Check All' box:

 

CType(RadGridView2.Columns("dni"), GridViewCheckBoxColumn).EnableHeaderCheckBox = True

 

Handling the click event in the header

Private Sub RadGridView1_ValueChanged(sender As Object, e As EventArgs) Handles RadGridView1.ValueChanged
    'notes:
    'CellValueChanged fires after the user leaves the fields.
    'The 'sender' will not be used, we'll get what we need through e.row and e.coumn
 
    'ValueChanged fires while the editor is still open, after every key stroke
    'normally, we'd avoid that but it's good for changes fired off by a check box header change
 
 
    Try
        'if this is called by a direct edit, we'll get an 'editor' control in the sender.
        'if this is called by a click in the check box editor HEADER, we get a GridViewCellInfo object
        If TypeOf (sender) Is RadCheckBoxEditor Or TypeOf (sender) Is RadTextBoxEditor Or TypeOf (sender) Is RadDateTimeEditor Then
            Exit Sub
        End If
        Dim ci As GridViewCellInfo = sender
        If ci.ColumnInfo.Name = "DNI" Then
            Me.RadGridView2.EndEdit()
            'Dim chk As RadCheckBoxEditor = CType(sender, RadCheckBoxEditor)
 
            Dim oRow As GridViewDataRowInfo = ci.RowInfo
            Dim oCol As GridViewDataColumn = ci.ColumnInfo
            Dim intRowID As Integer = oRow.Cells("RowID").Value
 
            'If TypeOf (oRow) Is GridViewFilteringRowInfo Then
            '    Exit Sub
            'End If
            Dim oSOP As New SOPIntegrationWork(intRowID)
            If oSOP.CUSTNMBR Is Nothing Then
                Exit Sub
            End If
            oSOP.DNI = Common.ToStr(oRow.Cells("DNI").Value)
 
            oSOP.save()
 
 
        End If
    Catch ex As Exception
        ErrorHandler.globalErrorHandler(ex, True)
    End Try
 
End Sub