RadGridView Custom Column Event - Get Info About Other Cells in the row

2 posts, 0 answers
  1. Simon
    Simon avatar
    32 posts
    Member since:
    Aug 2011

    Posted 12 Nov 2015 Link to this post

    I have added a custom column with a radSplitButton to my grid. When a button item is clicked, I would like to get the value from another cell in the row, delete the current row and delete other rows in the grid. I raise an event when a button item is clicked. I tried using the following code to subscribe to the event but the cellelement is nothing at this point. What is the best way to subscribe to the event?


      Private Sub dgvReconcile_CreateCell(sender As Object, e As Telerik.WinControls.UI.GridViewCreateCellEventArgs) Handles dgvReconcile.CreateCell
                If e.Column IsNot Nothing AndAlso Not e.CellElement Is Nothing Then
                    If e.Column.Name = "CreateNew" AndAlso (TypeOf e.Row Is GridDataRowElement OrElse TypeOf e.Row Is GridNewRowElement) Then
                        Dim myElement As SplitButtonCellElement = DirectCast(e.CellElement, SplitButtonCellElement)
                        AddHandler myElement.NewClicked, AddressOf btnCreateNew_Click
                    End If
                End If
            Catch ex As Exception
            End Try
        End Sub​

  2. Dimitar
    Dimitar avatar
    2983 posts

    Posted 13 Nov 2015 Link to this post

    Hi Simon,

    Thank you for writing.

    You can directly handle the click event in the custom cell element class. This way you will be able to unsubscribe from the event as well. You can also access the grid or any other required information inside the class:
    Friend Class ButtonCellElement
        Inherits GridDataCellElement
        Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement)
            MyBase.New(column, row)
        End Sub
        Private button As RadDropDownButtonElement
        Protected Overrides Sub CreateChildElements()
            button = New RadDropDownButtonElement()
            button.Text = "Test"
        End Sub
        Public Overrides Sub Attach(ByVal data As GridViewColumn, ByVal context As Object)
            MyBase.Attach(data, context)
            AddHandler button.Click, AddressOf button_Click
        End Sub
        Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim row = Me.RowInfo
            Dim otherCellValue = row.Cells("Name").Value.ToString()
        End Sub
        Public Overrides Sub Detach()
            AddHandler button.Click, AddressOf button_Click
        End Sub
        Public Overrides Function IsCompatible(ByVal data As GridViewColumn, ByVal context As Object) As Boolean
            Return TypeOf data Is ButtonColumn AndAlso TypeOf context Is GridDataRowElement
        End Function
    End Class

    Let me know if I can assist you further.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top