add commandbutton into each radgridview rows and How to control their click event

2 posts, 1 answers
  1. George C.
    George C. avatar
    29 posts
    Member since:
    Sep 2018

    Posted 06 Nov 2019 Link to this post


    I want to add commandbutton to each radgridview row, and I want to know how to define each row's button click event ?

    For example, If I click on button of row 3, the button shows a string in the cell instead and if clicked back again, the button hides string and shows itself.

    I use



  2. Answer
    Nadya avatar
    389 posts

    Posted 08 Nov 2019 Link to this post

    Hello George,

    I can suggest you to use GridViewCommandColumn which displays a button element on every row in RadGridView. The column responds to user input mouse clicks via the CommandCellClick event. You can handle the CellFormatting event in order to change the appearance of the button element and show the text that you want. Please refer to the following example which demonstrates this approach:

    PrivateSub SurroundingSub()
        Dim commandColumn As GridViewCommandColumn = New GridViewCommandColumn()
        commandColumn.Name = "CommandColumn"
        commandColumn.FieldName = "Title"
        commandColumn.HeaderText = "CommandColumn"
     AddHandler radGridView1.CommandCellClick, AddressOf RadGridView1_CommandCellClick
     AddHandler radGridView1.CellFormatting, AddressOf  RadGridView1_CellFormatting
     AddHandler radGridView1.CellClick, AddressOf  RadGridView1_CellClick
    Private Sub RadGridView1_CellClick(ByVal sender As Object, ByVal e As GridViewCellEventArgs)
        If TypeOf e.Column Is GridViewCommandColumn Then
            If radGridView1.CurrentCell.Tag IsNot Nothing Then
                radGridView1.CurrentCell.Tag = Nothing
            End If
        End If
    End Sub
    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
        If TypeOf e.CellElement Is GridCommandCellElement Then
            Dim cell As GridCommandCellElement = TryCast(e.CellElement, GridCommandCellElement)
            cell.DrawText = True
            cell.Text = "Test"
            If cell.Tag IsNot Nothing Then
                cell.CommandButton.Visibility = ElementVisibility.Collapsed
                cell.CommandButton.Visibility = ElementVisibility.Visible
            End If
        End If
    End Sub
    Private Sub RadGridView1_CommandCellClick(ByVal sender As Object, ByVal e As GridViewCellEventArgs)
        Dim cell As GridCommandCellElement = TryCast(sender, GridCommandCellElement)
        If cell.Tag Is Nothing Then
            cell.Tag = "Clicked"
        End If
    End Sub

    I hope this helps. Should you have any other questions do not hesitate to ask.

    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top