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

Remove backgound button on image button

4 Answers 31 Views
GridView
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 22 May 2014, 04:04 PM



Please see image attached. How do I get rid of the background button?

‚Äč
Private Sub grvVehicleList_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles grvVehicleList.CellFormatting
 
       If TypeOf e.CellElement Is GridCommandCellElement Then
 
           If e.Column.Name = "Delete" Then
 
               Dim button1 As RadButtonElement = TryCast(e.CellElement.Children(0), RadButtonElement)
               AddHandler button1.Click, AddressOf DeleteButton_Click
               button1.Image = My.Resources.validated
               button1.Text = Nothing
               e.CellElement.DrawText = False
 
           End If
 
           If e.Column.Name = "Validated" Then
 
               Dim buttonElement As RadButtonElement = DirectCast(e.CellElement.Children(0), RadButtonElement)
               buttonElement.UnbindProperty(RadButtonElement.ImageProperty)
               buttonElement.DisplayStyle = DisplayStyle.Image
               buttonElement.ImageAlignment = ContentAlignment.MiddleCenter
 
               If e.CellElement.RowInfo.Cells("Validated").Value = True Then
                   buttonElement.Image = My.Resources.validated
               Else
                   buttonElement.Image = My.Resources.Notvalidated
               End If
 
           End If
 
       End If
 
   End Sub

4 Answers, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 23 May 2014, 10:37 AM
Hi Jim, 

Thank you for contacting Telerik Support. 

In order to hide the buttons in the command column, you can set the CommandButton's Visibility property to Collapsed:
Private Sub radGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs)
    Dim cmdCell As GridCommandCellElement = TryCast(e.CellElement, GridCommandCellElement)
    If cmdCell IsNot Nothing Then
        cmdCell.CommandButton.Visibility = ElementVisibility.Collapsed 'hide the button
        'cmdCell.Image = Resources.folder_open ' set image to the cell if needed
    End If
End Sub

However, if you do not need a button, you can just use the GridViewImageColumn instead. More information about it is available here: http://www.telerik.com/help/winforms/gridview-columns-gridviewimagecolumn.html.

Another thing I noticed is that you are subscribing to the button click event in the formatting handler. This is not recommended and it will lead to multiple event subscriptions. To handle click of the button in a command cell, you can use the CommandCellClick event of the control. To handle any cell click, you can use the CellClick event of the control.

I hope this will help. Do not hesitate to write back with further questions.

Regards,
Ralitsa
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
William
Top achievements
Rank 1
answered on 23 May 2014, 01:03 PM
Thanks for the reply.
I've done the suggested and the button is gone. However, the CommandCellClick event does not fire.
All I'm trying to do is have an image instead of a button to remove the row from the grid.
Thanks for your help
0
William
Top achievements
Rank 1
answered on 23 May 2014, 01:05 PM
If e.CellElement.ColumnInfo.Name = "Delete" Then
 
           Dim cmdCell As GridCommandCellElement = TryCast(e.CellElement, GridCommandCellElement)
 
           If cmdCell IsNot Nothing Then
 
               cmdCell.CommandButton.Visibility = ElementVisibility.Collapsed 'hide the button
               cmdCell.Image = My.Resources.Delete
 
           End If
 
          End If
0
Ralitsa
Telerik team
answered on 26 May 2014, 09:45 AM
Hi Jim, 

Thank you for writing back.

When set the Visibility of CommandButton to Collapsed, the event CommandCellClick is not fired anymore. You can subscribe to the CellClick event and implement your logic.

If you use GridViewCommandColumn you can set the image as a background image and subscribe to CommandCellClick event and delete the row. Please see the attached demo project which demonstrate you how to delete row. 

If you decide to use a GridViewImageColumn (which I suggest), you need to subscribe to CellClick event and delete rows. Please take a look how to subscribe to the event: 
AddHandler RadGridView1.CellClick, AddressOf radGridView1_CellClick

Private Sub radGridView1_CellClick(sender As Object, e As GridViewCellEventArgs)
    Dim imageCell As GridImageCellElement = TryCast(sender, GridImageCellElement)
    'your click logic here
    If imageCell IsNot Nothing Then
    End If
End Sub

Should you have further questions, I would be glad to help.

Regards,
Ralitsa
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
William
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
William
Top achievements
Rank 1
Share this question
or