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

Center a button in a GridViewCommandColumn

4 Answers 38 Views
GridView
This is a migrated thread and some comments may be shown as answers.
QuizzBox
Top achievements
Rank 1
QuizzBox asked on 22 Mar 2018, 04:32 PM

hey, 

I'm using Windows 8 Theme in Telerik for Winforms 2018.1.116.40.

With this theme, in a GridViewCommandColumn, buttons are not really cutes, the cells likes grey and user doesn't see it's a button.

So, i want to reduce the size of buttons and center them in the cells.

I use command lines below in CellFormatting event

Dim button As RadButtonElement = CType(e.CellElement.Children(0), RadButtonElement)
button.Margin = New Padding(2)

In this case, some borders are no more visible (cf attached file).

Have you got an idea please ?

 

Subsidiary question : If on a condition, i only want my html text but without button i use the code in cellFormating event

element.CommandButton.ButtonFillElement.NumberOfColors = 1
element.CommandButton.ButtonFillElement.BackColor = Color.FromArgb(255, 255, 255, 255)
button.BorderElement.Visibility = ElementVisibility.Hidden

it works, but it's surely a poor code, i have tried too with 

button.BorderElement.Visibility = ElementVisibility.Hidden

and i don't see button and text.

If you have a better code ;)

Thanks for your help

--

Romain

 

 

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 23 Mar 2018, 12:02 PM
Hi Jean-Marc,

Thank you for writing

In the first case you can set the padding of the cell:
Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
    Dim cell = TryCast(e.CellElement, GridCommandCellElement)
    If cell IsNot Nothing Then
        cell.Padding = New Padding(5)
    End If
 
End Sub

For the second one, you should hide the button and show the cell text. If you are setting this uppon a condition you need to reset the visibility value. Here is the code:
Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
    Dim cell = TryCast(e.CellElement, GridCommandCellElement)
    If cell IsNot Nothing Then
        If e.RowIndex Mod 2 = 0 Then
            cell.CommandButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
            cell.Text = "Test"
        Else
            cell.CommandButton.Visibility = Telerik.WinControls.ElementVisibility.Visible
        End If
 
    End If
 
End Sub

Please let me know if there is something else I can help you with.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
QuizzBox
Top achievements
Rank 1
answered on 23 Mar 2018, 02:39 PM

Hi Dimitar, 

Thanks for your answer :)
Ok for 2nd problem, but for the 1st, still problem like attach file n°1.
On the attached file n°2, i've paint in yellow borders that i don't see.

Regards

 

0
Accepted
Dimitar
Telerik team
answered on 26 Mar 2018, 09:24 AM
Hi Jean,

There is an issue with the theme in the version that you are using. To workaround it, you can set the DrawBorder property:
Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
    Dim cell = TryCast(e.CellElement, GridCommandCellElement)
    If cell IsNot Nothing Then
        cell.Padding = New Padding(5)
        cell.DrawBorder = True
    End If
 
End Sub

This is fixed in the latest version and if you upgrade the border will be visible.

Please let me know if there is something else I can help you with. 

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
QuizzBox
Top achievements
Rank 1
answered on 26 Mar 2018, 09:35 AM
Thanks, works like a charm :)
Tags
GridView
Asked by
QuizzBox
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
QuizzBox
Top achievements
Rank 1
Share this question
or