This is a migrated thread and some comments may be shown as answers.

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

1 Answer 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 13 Nov 2015, 01:29 AM

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
        Try
            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
            MsgBox(ex.ToString)
        End Try
        
    End Sub​

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Nov 2015, 02:45 PM
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()
        MyBase.CreateChildElements()
 
        button = New RadDropDownButtonElement()
        button.Text = "Test"
        Me.Children.Add(button)
    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
        MyBase.Detach()
    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.

Regards,
Dimitar
Telerik
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
Tags
GridView
Asked by
Simon
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or