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

Button Link

3 Answers 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Blas
Top achievements
Rank 1
Blas asked on 08 Nov 2011, 04:47 PM
Hello,

I have a grid with dynamic columns, and for certain columns I need a button link that allows navigation to the master record related with the value (buttonlink.jpg).

For example, if colums show "Customer code", left to the customer code an arrow allows to open the form "Customer" and shows all the information related with such code.

This is the code to show the button:
Private Sub gridSELECT_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) _
        Handles gridSELECT.CellFormatting
       e.CellElement.Image = Nothing
       If e.CellElement.ColumnInfo.Name = "CardCode" AndAlso TypeOf e.CellElement.RowInfo Is GridViewDataRowInfo Then
           e.CellElement.ImageAlignment = ContentAlignment.MiddleLeft
           e.CellElement.Image = My.Resources.arrow_right
           e.CellElement.TextImageRelation = TextImageRelation.ImageBeforeText
       End If
 
   End Sub

How can I do to catch the click in this button? Is it possible?

3 Answers, 1 is accepted

Sort by
0
Blas
Top achievements
Rank 1
answered on 09 Nov 2011, 10:21 AM
Hello again

I finally made a Custom LinkCell that includes a button and a label. But I didn't figure out how to catch the click event for this button.

Class LinkCell
    Inherits GridDataCellElement
 
    Dim stack As StackLayoutElement
    Private boton As RadButtonElement
    Private label As RadLabelElement
 
    Public Sub New(column As GridViewColumn, rowElement As GridRowElement)
        MyBase.New(column, rowElement)
    End Sub
 
 
    Protected Overrides Sub SetContentCore(value As Object)
        boton.Text = ""
        boton.ToolTipText = value
 
        label.Text = value
 
    End Sub
 
      Protected Overrides Sub CreateChildElements()
        MyBase.CreateChildElements()
 
        boton = New RadButtonElement()
        boton.Margin = New System.Windows.Forms.Padding(0, 0, 0, 4)
        boton.StretchHorizontally = False
        boton.StretchVertically = False
        boton.Image = My.Resources.arrow_right
 
        boton.ButtonFillElement.GradientStyle = GradientStyles.Solid
        boton.ButtonFillElement.BackColor = Color.Transparent
        boton.BorderElement.ForeColor = Color.Transparent
        boton.BorderElement.Visibility = ElementVisibility.Hidden
 
 
        label = New RadLabelElement()
        label.StretchHorizontally = True
 
        stack = New StackLayoutElement
        stack.StretchHorizontally = True
        stack.StretchVertically = True
        stack.Visibility = True
 
        stack.Children.Add(boton)
        stack.Children.Add(label)
 
        stack.Visibility = ElementVisibility.Visible
 
        Me.Children.Add(stack)
    End Sub
    
End Class

Also, I have two more problems (linkcell.jpg)

1) I'd like to hide the border of the button (like the picture box of my previous example), but I'm not able to achieve that.
2) The vertical alignment of the custom cell in the row is top.Is it possible to align to the middle?

Thanks in advance



0
Blas
Top achievements
Rank 1
answered on 09 Nov 2011, 01:04 PM
Hello again

I finally did it replacing RadButtonElement with RadImageButtonElement, and using the margins to align vertically elements in the container.

For events I think that it's not possible to handle events in the form and they must be handle inside of the class. Is it right?

Main Form:
Private Sub gridSELECT_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs) Handles gridSELECT.CreateCell
      If TypeOf e.Row Is GridDataRowElement Then
          Select Case e.Column.Name.ToUpper
              Case "CARDCODE"
                  e.CellType = GetType(LinkCardCodeCell)
              Case ("OQUTDOCNUM")
                  e.CellType = GetType(LinkQuotationCell)
          End Select
      End If
  End Sub


LinkCell class and derived classes:

Class LinkCell
    Inherits GridDataCellElement
 
    Dim stack As StackLayoutElement
    Private boton As RadImageButtonElement
    Private label As RadLabelElement
 
    Public Sub New(column As GridViewColumn, rowElement As GridRowElement)
        MyBase.New(column, rowElement)
    End Sub
 
    Protected Overrides Sub SetContentCore(value As Object)
        boton.Text = ""
        boton.ToolTipText = value
        label.Text = value
    End Sub
 
    Protected Overrides Sub CreateChildElements()
        MyBase.CreateChildElements()
 
 
        boton = New RadImageButtonElement()
        boton.Margin = New System.Windows.Forms.Padding(0, 4, 0, 0)
        boton.StretchHorizontally = False
        boton.StretchVertically = False
        boton.Image = My.Resources.arrow_right
 
 
 
        boton.ButtonFillElement.GradientStyle = GradientStyles.Solid
        boton.ButtonFillElement.BackColor = Color.Transparent
        boton.BorderElement.GradientStyle = GradientStyles.Solid
        boton.BorderElement.ForeColor = Color.Transparent
        boton.BorderElement.Visibility = ElementVisibility.Hidden
 
        AddHandler boton.Click, AddressOf Boton_Click
 
 
        label = New RadLabelElement()
        label.Margin = New System.Windows.Forms.Padding(3, 5, 0, 0)
        label.StretchHorizontally = True
 
        stack = New StackLayoutElement
        stack.StretchHorizontally = True
        stack.StretchVertically = True
        stack.Visibility = True
 
        stack.Children.Add(boton)
        stack.Children.Add(label)
 
        stack.Visibility = ElementVisibility.Visible
 
        Me.Children.Add(stack)
    End Sub
 
 
    Protected Overridable Sub Boton_Click(sender As System.Object, e As System.EventArgs)
 
    End Sub
 
End Class
 
 
Class LinkQuotationCell
    Inherits LinkCell
    Public Sub New(column As GridViewColumn, rowElement As GridRowElement)
        MyBase.New(column, rowElement)
    End Sub
 
    Protected Overrides Sub Boton_Click(sender As System.Object, e As System.EventArgs)
        ShowLinkedObject(MyBase.Value, BoLinkedObject.lf_Quotation)
    End Sub
End Class
 
Class LinkCardCodeCell
    Inherits LinkCell
    Public Sub New(column As GridViewColumn, rowElement As GridRowElement)
        MyBase.New(column, rowElement)
    End Sub
 
    Protected Overrides Sub Boton_Click(sender As System.Object, e As System.EventArgs)
        ShowLinkedObject(MyBase.Value, BoLinkedObject.lf_BusinessPartner)
    End Sub
End Class

0
Alexander
Telerik team
answered on 11 Nov 2011, 03:16 PM
Hello Roberto,

Thank you for writing.

You can handle custom cell events in the form adding handlers for them when you create the cell in the CreateCell event of RadGridView:
Private Sub RadGridView1_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs) Handles RadGridView1.CreateCell
    Dim Cell As New CustomCell(e.Column, e.Row)
    ' Add handler for cell events
    e.CellElement = Cell
End Sub

I hope it helps.

Best regards,
Alexander
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
GridView
Asked by
Blas
Top achievements
Rank 1
Answers by
Blas
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or